我需要创建一个通过ajax请求生成的可单击单选按钮的列表。它们将如下所示:
10/15/2018
10/14/2018
10/13/2018
....
所以我正在下面进行Ajax调用并得到结果:
onTabChange: function (tabPanel, tab) {
if (tab.getTitle() == 'Reconciliation') {
Ext.Ajax.request({
url: '***',
reader: {
type: 'json',
rootProperty: 'data'
},
useDefaultXhrHeader: false,
withCredentials: true,
scope: this,
success: function (response) {
var selectReconciliation = this.lookupReference('lisatradereconciliation');
// Get the data from Ajax Request and shape it
var data = Ext.JSON.decode(response.responseText).data;
var reconciliationItems = [];
// Put the data into a shape that it will need to look like on the page
for (var i in data) {
reconciliationItems.push("boxLabel: '" + data[i].substr(5, 2) + "/" + data[i].substr(8, 2) + "/" + data[i].substr(0, 4) +"', name: 'rI', inputValue: 'data[i]'");
}
},
failure: function (response) {
'***'
}
});
}
},
然后我将其发送到如下视图单选项目:
items: [{
xtype: 'radiogroup',
fieldLabel: 'day',
items: reconciliationItems
}]
但这不起作用。
答案 0 :(得分:0)
reconciliationItems
数组应定义为全局变量,或者在ajax成功处理程序之外,以实现所需的功能:
在success
之外定义数组:
window.reconciliationItems = [];
然后像这样在success
处理程序中访问它:
success: function (response) {
var selectReconciliation = this.lookupReference('lisatradereconciliation');
// Get the data from Ajax Request and shape it
var data = Ext.JSON.decode(response.responseText).data;
// var reconciliationItems = []; <-- Dont define here
// Put the data into a shape that it will need to look like on the page
for (var i in data) {
reconciliationItems.push("boxLabel: '" + data[i].substr(5, 2) + "/" + data[i].substr(8, 2) + "/" + data[i].substr(0, 4) +"', name: 'rI', inputValue: 'data[i]'");
}
},