的json數據是這樣的:ExtJS的4:拿到店裏記錄值
({"success": "true", "message" : "OK","data":[{"id_metric":"1","name_filter":"doc filter","type_guicomp":"combobox"},{"id_metric":"1","name_filter":"severity","type_guicomp":"combobox"}]})
我希望能夠找回了"id_metric" = 1
的"type_guicomp"
字段值,那麼結果將是:"type_guicomp":"combobox"
和"type_guicomp":"combobox"
。
我這樣做是因爲我需要值"combobox"
將它分配給一個變量。 我已經試過幾件事情包括:
myStore.load({
scope: this,
callback : function(record, operation, success) {
console.log(record);
console.log(record.data);
}
和:
var index = Ext.StoreMgr.lookup("myStore").findExact('id_metric',1);
var rec = Ext.StoreMgr.lookup("myStore").getAt(index);
console.log(rec);
這些解決方案返回未定義或爲空。 所以,當我在回調做:
var i = myStore.getCount();
console.log(i);
它返回0
。但是,當我檢查JSON輸出時,它不是空的,而且實際上有數據。
我在做什麼錯?請任何幫助,將不勝感激。
編輯
我的店看起來是這樣的:
Ext.define('Metrics.store.MyStore', {
extend: 'Ext.data.Store',
model: 'Metrics.model.MyModel',
autoLoad: true,
idProperty: 'id_metric',
proxy : {
type : 'ajax',
actionMethods : 'POST',
node : 'id_metric',
api : {
read : 'gui_comp_items.php' //the php script that gets data from db
},
reader: {
type: 'json',
successProperty: 'success',
messageProperty: 'message',
root: 'data'
}
}
});
我的模型:
Ext.define('Metrics.model.MyModel', {
extend: 'Ext.data.Model',
fields: [
{name : 'id_metric', type : 'int'},
{name : 'name_filter', type : 'string'},
{name : 'type_guicomp', type : 'string'},
{name : 'value', type : 'string'}]
});
你的商店和模型配置是什麼樣的? – Geronimo 2013-02-27 17:25:52
我已將它們添加到我的帖子中。 – salamey 2013-02-28 08:36:18
據我記得,idProperty不是商店的屬性,但模型的所以考慮移動它,並與您返回兩個id_metric具有相同的值,所以它似乎並不唯一。此外,您可以縮短代碼'Ext.getStore('MyStore')。findRecord('id_metric',1)'。如果沒有像解碼問題那樣的錯誤,請用螢火蟲等方法仔細檢查響應。現在,嘗試在加載回調函數中轉儲數據,因爲在加載之前您可能會檢索它們。 – 2013-02-28 09:26:15