2012-12-03 44 views
1

我想讀取從數據庫返回的json的值。但我無法做到這一點。它給不明確。 在Firebug中,它給出了以下格式的正確值 {「COLUMNS」:[「B」,「C」,「D」,「E」,「F」,「G」], 「DATA」 [1.253,0.54,2.54,8.245,0,0.253]] }加載到商店後讀取json值

當我給console.log(response [0] .DATA.B)時,它給出undefined。 我試過alert(response [0] .get('B'));這也給未定義。 警報(成功)是真實的。

有人可以告訴我這裏出了什麼問題。

在此先感謝.. 這裏是我如果你不使用你自己的閱讀器使用

Ext.define('DBRec', { 
extend: 'Ext.data.Model', 
fields: [ 
{name:'A', type :'string'}, 
{name:'B', type:'string'}, 
{name:'C', type:'string'}, 
{name:'D', type:'string'}, 
{name:'E', type:'string'}, 
{name:'F', type:'string'}, 
{name:'G', type:'string'} 
] 
}); 

var DBRecStore=Ext.create('Ext.data.Store', { 
model: 'DBRec', 
proxy: { 
type: 'ajax', 
url : 'dbFunctions.cfc?method=getRec', 
reader: { 
    type:'json', 
    root:'DATA', 
    fields: ['B', 'C', 'D', 'E', 'F', 'G'] 
    } 
} 
}); 

function loadLimits() 
{ 
    DBRecStore.load({ 
    params: { 
    reader: 'json', 
    returnFormat: 'JSON' 
    }, 
callback: function(response, options, success){ 
    alert(DBRecStore.getCount()); 
    if (DBRecStore.getCount() == '0') { 
     alert("no records found"); 

    } 
    else 
    { 
     alert("records found"); 
     console.log(response[0].DATA.B+" "+response[0].DATA.C); 
    } 
} 
}); 

} 

回答

0

的代碼,因爲我看到你沒有,那麼你的數據數組必須是一個對象數組,而不是數組的數組。

{ "DATA":[{a:1.253,b: 0.54,c: 2.54,d:8.245,e:0,0.253}] }

而且你不需要在商店界定領域,它已經在模型。

+0

奇才..所以我將如何獲得該數組的值? – user1049057

+0

如果你不想改變你的傳入數據 - 讓你的讀者。您可以擴展:http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.reader.Json – Damask

+0

我無法改變服務器響應。我試圖給讀者:{type:'json',根:'COLUMNS',記錄:'DATA',字段:['B','C','D','E','F','G ']}但它仍然沒有提示db的值。 – user1049057