错误:“this.proxy”为 null 或不是 EXTJS 中的对象

发布于 2024-11-26 22:04:04 字数 1335 浏览 3 评论 0原文

当我运行此 EXTJS 代码时,我收到错误 'this.proxy' 为 null 或不是对象。你能帮我解决这个问题吗?

var myData = [
                   ['J', 'MD'],
                   ['A', 'VA'],
                   ['S', 'DC'],
                   ['M', 'DE'],
                   ['B', 'NJ'],
                   ['N', 'CA'],
                   ['S', 'RT'],
                   ['S', 'CG']
                 ];
 var store = new Ext.data.ArrayStore({
        totalProperty : 8,
        autoLoad : {
            params : {
                start : 0,
                limit : 4
            }
        },
        fields : [ {
            name : 'fullName'
        }, {
            name : 'state'
        } ]
    });

 store.loadData(myData);
 var grid = new Ext.grid.GridPanel({
    store : store,
    columns : [ {
        id : 'fullName',
        header : "FullName",
        width : 160,
        sortable : true,
        dataIndex : 'fullName'
    }, {
        header : "State",
        width : 75,
        sortable : true,
        dataIndex : 'state'
    } ],
    stripeRows : true,
    autoExpandColumn : 'fullName',
    height : 350,
    width : 600,
    title : 'Array Grid',
    bbar : new Ext.PagingToolbar({
        store : store,
        pageSize : 4,
        displayInfo : true
    }),
    viewConfig : {
        forceFit : true
    }
 });

When i ran this EXTJS code,i got an error 'this.proxy' is null or not an object. Can you help me out regarding this,plzz ?

var myData = [
                   ['J', 'MD'],
                   ['A', 'VA'],
                   ['S', 'DC'],
                   ['M', 'DE'],
                   ['B', 'NJ'],
                   ['N', 'CA'],
                   ['S', 'RT'],
                   ['S', 'CG']
                 ];
 var store = new Ext.data.ArrayStore({
        totalProperty : 8,
        autoLoad : {
            params : {
                start : 0,
                limit : 4
            }
        },
        fields : [ {
            name : 'fullName'
        }, {
            name : 'state'
        } ]
    });

 store.loadData(myData);
 var grid = new Ext.grid.GridPanel({
    store : store,
    columns : [ {
        id : 'fullName',
        header : "FullName",
        width : 160,
        sortable : true,
        dataIndex : 'fullName'
    }, {
        header : "State",
        width : 75,
        sortable : true,
        dataIndex : 'state'
    } ],
    stripeRows : true,
    autoExpandColumn : 'fullName',
    height : 350,
    width : 600,
    title : 'Array Grid',
    bbar : new Ext.PagingToolbar({
        store : store,
        pageSize : 4,
        displayInfo : true
    }),
    viewConfig : {
        forceFit : true
    }
 });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光暖心i 2024-12-03 22:04:04

您不能同时使用内存代理autoLoad配置以及store.loadautoLoad 配置和 store.load 只能与用于实际加载数据的代理(例如 Ajax 代理)一起使用。

但是,您可以使用 Direct代理。在这种情况下,您必须创建将扮演服务器端角色的直接函数

var myData = [
['J', 'MD'],
...
];
var myDirectfn = function(opts, fn, proxy){
  var start = opts.start, end = opts.page*opts.limit;
  var data = [];
  if (end > myData.length)
    end = myData.length;
  for (var i = start; i < end; i++)
    data.push(myData[i]);
  fn(0, {status: true, result: data});
};

//Why am I doing this? I don't know, but otherwise store will throw exception
myDirectfn.directCfg={method : {}};

var store = new Ext.data.Store({
  //totalProperty : 8, 
  pageSize: 4,
  proxy: {
    type: 'direct',
    directFn: myDirectfn,
    reader: {type: 'array'}
  },
  fields : [ {name : 'fullName'}, {name : 'state'} ]
});

这里是可以玩的小提琴。

更新

对于extjs3直接代理方法如下所示:

var myDirectfn = function(opts, fn, proxy) {
    var start = opts.start,
        end = opts.limit+opts.start,
        data = [];
    if (end > myData.length) end = myData.length;
    for (var i = start; i < end; i++)
        data.push(myData[i]);
    data.total = myData.length;
    fn(data, {
        status: true,
        result: data
    });
};
myDirectfn.directCfg = {
    method: {len:1}
};
var store = new Ext.data.ArrayStore({
    proxy: new Ext.data.DirectProxy({
        directFn: myDirectfn
    }),
    fields: [{
        name: 'fullName'},
    {
        name: 'state'}]
})

store.load({params: {start: 0, limit: 4}});

这里是演示。而且似乎您可以通过使用 这个插件

You cannot at the same time use memory proxy and autoLoad config as well as store.load. autoLoad config and store.load can only be used with proxies that are intended for actual loading of data like Ajax proxy.

However, you can use Direct proxy. In this case you will have to create your direct-function which will play role of server-side.

var myData = [
['J', 'MD'],
...
];
var myDirectfn = function(opts, fn, proxy){
  var start = opts.start, end = opts.page*opts.limit;
  var data = [];
  if (end > myData.length)
    end = myData.length;
  for (var i = start; i < end; i++)
    data.push(myData[i]);
  fn(0, {status: true, result: data});
};

//Why am I doing this? I don't know, but otherwise store will throw exception
myDirectfn.directCfg={method : {}};

var store = new Ext.data.Store({
  //totalProperty : 8, 
  pageSize: 4,
  proxy: {
    type: 'direct',
    directFn: myDirectfn,
    reader: {type: 'array'}
  },
  fields : [ {name : 'fullName'}, {name : 'state'} ]
});

And here is fiddle to play arround with.

UPDATE

For extjs3 Direct Proxy method would look like this:

var myDirectfn = function(opts, fn, proxy) {
    var start = opts.start,
        end = opts.limit+opts.start,
        data = [];
    if (end > myData.length) end = myData.length;
    for (var i = start; i < end; i++)
        data.push(myData[i]);
    data.total = myData.length;
    fn(data, {
        status: true,
        result: data
    });
};
myDirectfn.directCfg = {
    method: {len:1}
};
var store = new Ext.data.ArrayStore({
    proxy: new Ext.data.DirectProxy({
        directFn: myDirectfn
    }),
    fields: [{
        name: 'fullName'},
    {
        name: 'state'}]
})

store.load({params: {start: 0, limit: 4}});

Here is demo. And also it appears that you can utilise memory proxy with loading by using this plugin

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文