2014-01-07 129 views
0

我有一个通过代理收集数据的商店。我使用这些数据成功创建了一个ItemList。Sencha Touch 2分配变量

我的问题是我试图将数据从商店分配给变量供以后使用。

我可以使用数据的唯一位置是:

itemTpl: '{term} - {tid}', 

第一可变(项)是一个字符串,TID是整数。我需要单独使用整数,但似乎我不能使用除上述格式以外的数据。

回答

0

如果您在YourApp/store目录中定义Sencha Touch商店,则可以全局使用商店(及其数据)。

一个例子:

你的模型&商店可以是这样的......

Ext.define('YourApp.model.Example', { 
    extend: 'Ext.data.Model', 

    config: { 
     fields: [ 
      {name: 'id', type: 'int'}, 
      {name: 'term', type: 'string'} 
     ] 
    } 
}); 


Ext.define('YourApp.store.Example', { 
    extend: 'Ext.data.Store', 

    config: { 
     storeId:'exampleStore', 
     model: 'YourApp.model.Example', 
     proxy: {} //your proxy config 
    } 
}); 

如果有人口稠密商店(如你似乎有),你可以用它来填充选择字段,列出...无论使用它的storeId。

{ 
    xtype: 'selectfield', 
    label: 'Term', 
    name: 'term', 
    store: 'exampleStore', //storeId 
    displayField: 'term', 
    valueField: 'id' 
} 

或者您也可以访问存储,它的使用手动商店getData()getRange()方法的数据。 (见http://docs.sencha.com/touch/2.3.1/#!/api/Ext.data.Store

var store = Ext.getStore('exampleStore'); //storeId 
console.log(store.getData().all[index_of_record]); //record 
console.log(store.getData().all[index_of_record].data); //data object 

console.log(store.getData().all[index_of_record].data.id); //id property 
console.log(store.getData().all[index_of_record].data.term); //term property 
+0

老兄!非常感谢你。一周的疼痛快要结束了。谢谢 – sisko