论坛首页 AJAX版 EXT

Ext2.1使用HttpProxy和JsonReader取数的问题。

浏览 429 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
最后更新时间:2008-05-28
代码如下:
Ext.onReady(function(){

     // create the Data Store
     var ds = new Ext.data.Store({
         // load using HTTP
         proxy: new Ext.data.HttpProxy({url: 'http://localhost:8080/MyExt/test/json.do?method=execute'}),//

         // the return will be XML, so lets set up a reader
         reader: new Ext.data.JsonReader({
                // records will have an "Item" tag
                root:"BOOKARRAY"//
            }, [
                // set up the fields mapping into the xml doc
                // The first needs mapping, the others are very basic
               'KEYWORDS','ISBN','Title', 'Manufacturer', 'ProductGroup'
            ])
     });

     var cm = new Ext.grid.ColumnModel([
      {header: "KEYWORDS", dataIndex: 'KEYWORDS'},
      {header: "ISBN", dataIndex: 'ISBN'},
      {header: "Title",   dataIndex: 'Title'},
      {header: "Manufacturer",   dataIndex: 'Manufacturer'},
      {header: "Product Group", dataIndex: 'ProductGroup'}
     ]);
     cm.defaultSortable = true;

     // create the grid
     var grid = new Ext.grid.GridPanel({
         renderTo:"hello",
         title:"Json测试",
         ds: ds,
         cm: cm
     });
     ds.load();

     
  });

表格出来了,但是没有取到后台数据填充。
直接访问取数的URL
引用
'http://localhost:8080/MyExt/test/json.do?method=execute

可以得到如下结果:
引用
{"itemList":[{"menuid":"1111","menuName":"wwwwwwwww","url":"http://www.baidu.com"},{"menuid":"1111","menuName":"wwwwwwwww","url":"http://www.baidu.com"},{"menuid":"1111","menuName":"wwwwwwwww","url":"http://www.baidu.com"},{"menuid":"1111","menuName":"wwwwwwwww","url":"http://www.baidu.com"},{"menuid":"1111","menuName":"wwwwwwwww","url":"http://www.baidu.com"}]}

所以可以判断是前台代码有问题,各位帮看看。
   
最后更新时间:2008-05-28
aixy 写道
代码如下:
Ext.onReady(function(){

     // create the Data Store
     var ds = new Ext.data.Store({
         // load using HTTP
         proxy: new Ext.data.HttpProxy({url: 'http://localhost:8080/MyExt/test/json.do?method=execute'}),//

         // the return will be XML, so lets set up a reader
         reader: new Ext.data.JsonReader({
                // records will have an "Item" tag
                root:"BOOKARRAY"//
            }, [
                // set up the fields mapping into the xml doc
                // The first needs mapping, the others are very basic
               'KEYWORDS','ISBN','Title', 'Manufacturer', 'ProductGroup'
            ])
     });

     var cm = new Ext.grid.ColumnModel([
      {header: "KEYWORDS", dataIndex: 'KEYWORDS'},
      {header: "ISBN", dataIndex: 'ISBN'},
      {header: "Title",   dataIndex: 'Title'},
      {header: "Manufacturer",   dataIndex: 'Manufacturer'},
      {header: "Product Group", dataIndex: 'ProductGroup'}
     ]);
     cm.defaultSortable = true;

     // create the grid
     var grid = new Ext.grid.GridPanel({
         renderTo:"hello",
         title:"Json测试",
         ds: ds,
         cm: cm
     });
     ds.load();

     
  });

表格出来了,但是没有取到后台数据填充。
直接访问取数的URL
引用
'http://localhost:8080/MyExt/test/json.do?method=execute

可以得到如下结果:
引用
{"itemList":[{"menuid":"1111","menuName":"wwwwwwwww","url":"http://www.baidu.com"},{"menuid":"1111","menuName":"wwwwwwwww","url":"http://www.baidu.com"},{"menuid":"1111","menuName":"wwwwwwwww","url":"http://www.baidu.com"},{"menuid":"1111","menuName":"wwwwwwwww","url":"http://www.baidu.com"},{"menuid":"1111","menuName":"wwwwwwwww","url":"http://www.baidu.com"}]}

所以可以判断是前台代码有问题,各位帮看看。

grid没有render,再看看例子吧。想要深入研究Ext,多看看源码 Ext的source文件夹下的那些js文件,能有很多收获。
   
0 请登录后投票
最后更新时间:2008-05-28
代码后面改成这样:
// create the grid
     var grid = new Ext.grid.GridPanel({
         renderTo:"hello",
         title:"Json测试",
         ds: ds,
         cm: cm
     });
     grid.render();
     ds.load();

还是出不来
   
0 请登录后投票
最后更新时间:2008-05-28
render需要界面占位div的id。
如Ext的例子中

grid.render('grid-example');


API文档关于render
render( [Mixed container], [String/Number position] ) : void 
If this is a lazy rendering component, render it to its container element.
If this is a lazy rendering component, render it to its container element. 
Parameters:
 
container : Mixed
(optional) The element this component should be rendered into. If it is being applied to existing markup, this should be left off.
position : String/Number
(optional) The element ID or DOM node index within the container before which this component will be inserted (defaults to appending to the end of the container)
Returns: 
void


GridPanel用到的render是Ext.Component的render
/**
     * If this is a lazy rendering component, render it to its container element.
     * @param {Mixed} container (optional) The element this component should be rendered into. If it is being
     * applied to existing markup, this should be left off.
     * @param {String/Number} position (optional) The element ID or DOM node index within the container <b>before</b>
     * which this component will be inserted (defaults to appending to the end of the container)
     */
    render : function(container, position){
        if(!this.rendered && this.fireEvent("beforerender", this) !== false){
            if(!container && this.el){
                this.el = Ext.get(this.el);
                container = this.el.dom.parentNode;
                this.allowDomMove = false;
            }
            this.container = Ext.get(container);   //在这将占位的和自身容器联系到一起
            if(this.ctCls){
                this.container.addClass(this.ctCls);
            }
            this.rendered = true;
            if(position !== undefined){
                if(typeof position == 'number'){
                    position = this.container.dom.childNodes[position];
                }else{
                    position = Ext.getDom(position);
                }
            }
            this.onRender(this.container, position || null);
            if(this.autoShow){
                this.el.removeClass(['x-hidden','x-hide-' + this.hideMode]);
            }
            if(this.cls){
                this.el.addClass(this.cls);
                delete this.cls;
            }
            if(this.style){
                this.el.applyStyles(this.style);
                delete this.style;
            }
            this.fireEvent("render", this);
            this.afterRender(this.container);
            if(this.hidden){
                this.hide();
            }
            if(this.disabled){
                this.disable();
            }

            this.initStateEvents();
        }
        return this;
    }
   
0 请登录后投票
最后更新时间:2008-05-28
谢谢shatuo,已经弄出来了,纯粹是我粗心导致的。
   
0 请登录后投票
论坛首页 AJAX版 EXT

跳转论坛:
JavaEye推荐