我喜欢从 ExtJs 中的 JSon 响应填充 checkboxgroup。单击发送按钮时,它将在控制台中显示响应。
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 : function(){
请建议我解决此问题。