我有formpanel
有文本字段
{
xtype: 'textfield',
name: name,
listeners: {
change: function( field, newValue, oldValue, eOpts ){
alert(newValue) // [object Object],[object Object],[object Object]
}
}
}
我使用form.load({...});
将值加载到textfield
这是我的json
{
"success":true,
"data":{
"name":[
{"dis":3,"val":0},
{"dis":2,"val":1},
{"dis":1,"val":2}
]
}
}
如何阅读dis
函数中的val
和change
。我alert(newValue)
看起来像
[object Object],[object Object],[object Object]
修改
alert(newValue[0]);
值为[
。newValue
的{{1}}结果为alert(typeof newValue);
,我尝试将其转换为json,如 string
但我收到错误
var json = eval("(" + newValue + ")");
答案 0 :(得分:0)
您可以使用以下
将JSON字符串解析为JavaScript对象 var json = Ext.decode(jsonString);
然后您可以访问这些成员:
console.log(json.success);
答案 1 :(得分:0)
我找到了解决方案。我的json必须看起来像
{
"success":true,
"data":{
"name":[
{\"dis\":3,\"val\":0},
{\"dis\":2,\"val\":1},
{\"dis\":1,\"val\":2}
]
}
}
之后使用Ext.decode(newValue);
:)