閱讀對象我有一個formpanel
,有一個文本框如何ExtJS的4
{
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}
]
}
}
哪有我在change
函數中讀取dis
和val
。我alert(newValue)
看起來像 [object Object],[object Object],[object Object]
編輯
- 但我儘量
alert(newValue[0]);
值[
。 - 我打印像
alert(typeof newValue);
結果newValue
類型爲string
,我嘗試將其轉換成JSON像
var json = eval("(" + newValue + ")");
,但我得到的錯誤
SyntaxError: missing ] after element list
([object Object],[object Object],[object Object])
後不要使用調試警報(...)。這是非常低效的。改用console.log(newValue)。這會將變量打印到您的調試控制檯,PLUS具有能夠打印對象的全部內容的好處,而不僅僅是簡單的值。 – existdissolve
@existdissolve我使用它,但仍然得到'[對象對象],[對象對象],[對象對象]':( – LookAtMeNow
你使用哪個瀏覽器? – existdissolve