2013-02-28 45 views
0

我正在使用ExtJs 4.1。为什么不是autoLoad的商店项目数量是0?

我有一个这样的商店:

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'})一段时间later.after我已经做到了这一点,它使用predictTargetStore组合框将有选择。 但是当我试图从商店得到一个项目,我failed.I这样做:

predictTargetStore.load({ 
    url : 'getPredictTargetList.action' 
}); 
var value = predictTargetStore.getAt(0).get('value'); 

我发现predictTargetStore.getAt(0)为空和predictTargetStore.getCount()为0 因此如何我可以得到商店的一个项目吗? 非常感谢你!

回答

1

我试过了,下面会做的伎俩:

user.load({ 
    scope: this, 

    callback: function(records, operation, success) { 
    user.each(function(record) { 
     console.log(record.get('name')); 
    }); 
    } 
}); 
+0

非常感谢!它的工作原理! – 2013-03-01 06:30:24

-1

我认为您需要在代理内提及url,或者您需要使用商店中的setProxy()方法来设置URL。不这样做,值可能不会返回。查看sencha文档了解更多信息。

+2

-1,负载是异步的,负载处理需要在回调发生。 – 2013-02-28 10:42:24

+0

非常感谢你! – 2013-03-01 06:31:16

1

等待服务器响应:关于callback功能here

predictTargetStore.load({ 
    url : 'getPredictTargetList.action', 
    callback: function() { 
     var value = predictTargetStore.getAt(0).get('value'); 
    } 
}); 

详细信息。

0

我穿过类似的问题想出了如下代码: 数据属性`

Ext.define('MyApp.model.EOrder.Model.TestRequest', { 
    extend : 'Ext.data.Model', 
    fields : [{ 
      name : 'testId', 
      type : 'int' 
     }, { 
      name : 'testCode' 
     }, { 
      name : 'testName' 
     }, { 
      name : 'price', 
      type : 'float' 
     } 
    ] 
}); 

var testStagingStore = Ext.create('Ext.data.Store', { 
     model : 'MyApp.model.EOrder.Model.TestRequest', 
     storeId : 'StagingTestRequest', 
     autoLoad : false, 
     proxy : { 
      type : 'ajax', 
      url : 'LOINC.json', 
      reader : { 
       type : 'json', 
       root : 'TestRequest' 
      } 
     }, 
     listeners : { 
      load : function() { 
       loadedCount = this.data.getCount(); 
       console.log('json file loaded. processed records:' + loadedCount); 
      } 
     } 
    }); 

testStagingStore.load(); 

console.log(testStagingStore.data.items); // in chrome "network" console, I know my json file was loaded successfully. But here I get nothing! 

`

不知道是否妥当,不填充。

我相信你有同样的问题,因为getAt将从数据属性中检索记录。

+0

我找到了解决方案: – user650749 2013-03-01 01:39:52