我喜歡在ExtJs中從JSon響應中填充複選框組。當發送按鈕點擊它將在控制檯中顯示響應。SyntaxError:函數語句需要ExtJs中的名稱
Ext.define('myclass', {
extend: 'Ext.form.Panel',
initComponent: function(){
Ext.apply(this, {
renderTo: Ext.getBody(),
title: 'Message',
tbar: [{
text: 'Send',
handler: function(){
console.log(this.getValues());
},
scope: this
}],
items: []
});
this.callParent(arguments);
}
});
var messagePanel = new myclass();
loadCheckboxes : function(){
Ext.Ajax.request({
url: 'recipients.json',
success: function(response){
console.log(response);
},
scope: this
});
}
this.loadCheckboxes();
onLoad : function(response){
var jsonResponse = Ext.decode(response.responseText);
if (jsonResponse.success) {
// success
console.log(jsonResponse);
}
}
Ext.Ajax.request({
url: 'recipients.json',
success: onLoad(),
scope: this
});
var checkboxGroup = {
xtype: 'checkboxgroup',
columns: 2,
fieldLabel: 'Recipients',
name: 'recipients',
style: {
padding: '10px'
},
items: []
};
this.add(checkboxGroup);
var i, len = jsonResponse.recipients.length, recipient;
for (i = 0; i < len; i++) {
recipient = jsonResponse.recipients[i];
checkboxGroup.items.push({
xtype: 'checkbox',
boxLabel: recipient.fullName,
name: 'recipients',
inputValue: recipient.userID,
checked: recipient.selected
});
}
這是此代碼的Json代碼。
{
"success": true,
"recipients": [{
"fullName": "Stuart Ashworth",
"userID": 1,
"selected": true
}, {
"fullName": "Andrew Duncan",
"userID": 2,
"selected": false
}
]
}
當我運行此代碼,在控制檯中顯示錯誤。 語法錯誤:函數語句需要一個名字 loadCheckboxes:函數(){
請給我建議對這個問題的解決方案。
一些縮進將是很好 –
'VAR messagePanel =新MyClass的();'和'loadCheckboxes:函數(){'不能有效在一起。一個是變量聲明(在對象文本中無效),另一個是對象文字鍵或標籤+匿名函數聲明(與匿名函數表達式不同,這是不允許的)。 –
爲此提出工作解決方案。 –