0
我有一個通過代理收集數據的商店。我使用這些數據成功創建了一個ItemList。Sencha Touch 2分配變量
我的問題是我試圖將數據從商店分配給變量供以後使用。
我可以使用數據的唯一位置是:
itemTpl: '{term} - {tid}',
第一可變(項)是一個字符串,TID是整數。我需要單獨使用整數,但似乎我不能使用除上述格式以外的數據。
我有一個通過代理收集數據的商店。我使用這些數據成功創建了一個ItemList。Sencha Touch 2分配變量
我的問題是我試圖將數據從商店分配給變量供以後使用。
我可以使用數據的唯一位置是:
itemTpl: '{term} - {tid}',
第一可變(項)是一個字符串,TID是整數。我需要單獨使用整數,但似乎我不能使用除上述格式以外的數據。
如果您在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
老兄!非常感謝你。一週的疼痛快要結束了。謝謝 – sisko