[英]How to read object in Extjs 4
I have a formpanel
that has a textfield 我有一个formpanel
文本字段的formpanel
{
xtype: 'textfield',
name: name,
listeners: {
change: function( field, newValue, oldValue, eOpts ){
alert(newValue) // [object Object],[object Object],[object Object]
}
}
}
I using form.load({...});
我使用form.load({...});
to load value to textfield
将值加载到textfield
Here is my json 这是我的json
{
"success":true,
"data":{
"name":[
{"dis":3,"val":0},
{"dis":2,"val":1},
{"dis":1,"val":2}
]
}
}
How can I read dis
and val
in change
function. 如何在change
功能中读取dis
和val
。 I alert(newValue)
look like [object Object],[object Object],[object Object]
我alert(newValue)
看起来像[object Object],[object Object],[object Object]
Edit 编辑
alert(newValue[0]);
但是我尝试alert(newValue[0]);
value is [
. 值是[
。 newValue
like alert(typeof newValue);
我打印newValue
类型,例如alert(typeof newValue);
result is string
and I try to convert it to json like 结果是string
,我尝试将其转换为json var json = eval("(" + newValue + ")");
But I get error 但是我得到了错误
SyntaxError: missing ] after element list
([object Object],[object Object],[object Object])
You can parse a JSON string into a JavaScript object using the following 您可以使用以下方法将JSON字符串解析为JavaScript对象
var json = Ext.decode(jsonString);
Then you can access the members as such: 然后,您可以像这样访问成员:
console.log(json.success);
I found solution. 我找到了解决方案。 My json must be look like 我的json必须看起来像
{
"success":true,
"data":{
"name":[
{\"dis\":3,\"val\":0},
{\"dis\":2,\"val\":1},
{\"dis\":1,\"val\":2}
]
}
}
And after that using Ext.decode(newValue);
然后使用Ext.decode(newValue);
:) :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.