错误:'this.proxy'为空或不是EXTJS中的对象 [英] Error: 'this.proxy' is null or not an object in EXTJS
问题描述
当我运行这个EXTJS代码时,我收到一个错误'this.proxy'为null或不是一个对象。你能帮我解决这个问题吗?
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
}
});
推荐答案
您不能同时使用内存代理
和 autoLoad
config以及 store.load
。 autoLoad
config和 store.load
只能用于实际加载数据的代理,如 Ajax
代理。
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.
但是,您可以使用 Direct
代理。在这种情况下,您将必须创建直接函数
,这将扮演服务器端
的角色。
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.
更新
对于extjs3直接代理方法将如下所示:
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}});
这里是演示。而且看起来您可以使用 load
ing使用内存代理,方法是使用这个插件
Here is demo. And also it appears that you can utilise memory proxy with load
ing by using this plugin
这篇关于错误:'this.proxy'为空或不是EXTJS中的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!