Extjs 为什么商店中非自动加载的项目计数为0?
我使用的是ExtJS4.1 我有一家这样的商店:Extjs 为什么商店中非自动加载的项目计数为0?,extjs,extjs4.1,Extjs,Extjs4.1,我使用的是ExtJS4.1 我有一家这样的商店: var predictTargetStore = new Ext.create('Ext.data.Store',{ autoLoad : false, fields: ['label','value'], proxy : { type : 'ajax', reader : { type : 'json', root : 'predictTar
var predictTargetStore = new Ext.create('Ext.data.Store',{
autoLoad : false,
fields: ['label','value'],
proxy : {
type : 'ajax',
reader : {
type : 'json',
root : 'predictTargetList'
}
}
});
predictTargetStore.load({
url : 'getPredictTargetList.action'
});
var value = predictTargetStore.getAt(0).get('value');
稍后我将执行predictTargetStore.load({url:'getPredictTargetList.action'})。完成此操作后,使用predictTargetStore的组合框将有选择。
但当我尝试从商店购买一件商品时,我失败了。我喜欢这样:
var predictTargetStore = new Ext.create('Ext.data.Store',{
autoLoad : false,
fields: ['label','value'],
proxy : {
type : 'ajax',
reader : {
type : 'json',
root : 'predictTargetList'
}
}
});
predictTargetStore.load({
url : 'getPredictTargetList.action'
});
var value = predictTargetStore.getAt(0).get('value');
我发现predictTargetStore.getAt(0)为null,predictTargetStore.getCount()为0。
那么我怎样才能买到店里的一件商品呢?
多谢各位 我认为您需要在代理中提及
url
,或者您需要使用存储上的setProxy()
方法来设置url。如果不这样做,值可能不会返回。查看sencha文档以了解更多信息。等待服务器响应:
predictTargetStore.load({
url : 'getPredictTargetList.action',
callback: function () {
var value = predictTargetStore.getAt(0).get('value');
}
});
有关
回调函数的详细信息。我遇到了与以下代码类似的问题:
`
`
不确定数据属性是否正确填充
我相信您也有同样的问题,因为getAt将从数据属性检索记录 我试过了,下面的方法就可以了:
user.load({
scope: this,
callback: function(records, operation, success) {
user.each(function(record) {
console.log(record.get('name'));
});
}
});
-1、加载是异步的,加载处理需要在回调中进行。