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);
}
}
});
}
奇才..所以我将如何获得该数组的值? – user1049057
如果你不想改变你的传入数据 - 让你的读者。您可以扩展:http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.reader.Json – Damask
我无法改变服务器响应。我试图给读者:{type:'json',根:'COLUMNS',记录:'DATA',字段:['B','C','D','E','F','G ']}但它仍然没有提示db的值。 – user1049057