[英]How to parse JSON values and populate to combobox using EXTJS 4.2.1?
方法:
Ext.Ajax.request({
url: 'url',
method: 'GET',
timeout: 60000,
params: {
"perviceTypeId": my.rec.data.prepeId
},
success: function(response) {
var jsonResp = response.responseText;
console.log("ajax data responseText::" + jsonResp);
//how to parse value and display and populate to deageType combobox
var combo = Ext.getCmp('deageType');
}
});
响应为 JSON:
{
"message": null,
"data": [
{
"value": "ESS",
"display": "ESS"
},
{
"value": "ANS",
"display": "ANS"
}
],
"errorCode": -1,
"totalCount": 1,
"messages": null,
"resultDate": 1615282701392,
"success": true
}
你可以这样做:
var combo = Ext.getCmp('myCombo');
combo.store = Ext.create('Ext.data.Store', {
fields: ['value', 'display'],
data: responseJSON.data
});
这是该示例的功能小提琴: https://fiddle.sencha.com/#view/editor&fiddle/3cb0
您应该解码响应(使用Ext.JSON.decode
)并将商店(使用bindStore
)绑定到组合:
例子:
Ext.Ajax.request({
url: 'url',
method: 'GET',
timeout: 60000,
params: {
"perviceTypeId": my.rec.data.prepeId
},
success: function(response) {
var jsonResp = Ext.JSON.decode(response.responseText);
var combo = Ext.getCmp('deageType');
combo.bindStore(Ext.create('Ext.data.Store', {
fields: ['display', 'value'],
data: jsonResp['data']
}));
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.