【发布时间】:2014-03-16 19:08:18
【问题描述】:
我正在尝试使用 jsonStore 将 json 数据加载到我的组合框。 商店正在使用 PHP 从服务器中检索数据。
我可以看到服务器正在使用正确的 json 数据处理 PHP 请求和响应,但不知何故组合框保持为空。
相关代码:
商店和 ComboBox - ComboBox 在 FormPanel 内:
var groupsStore= new Ext.data.JsonStore({url:'login.php?action=getGroups',
root: 'entities',
fields: [{name:'groupName', mapping:'groupName'}]
});
LoginWin = function(cfg) {
this.form = new Ext.form.FormPanel({
labelWidth:60, baseCls:'x-plain', autoHeight:true, style:'padding:5px',
items:[
{xtype:'combo', name:'groups', fieldLabel:'Group', store:groupsStore,
displayField:'groupName', valueField:'groupName', emptyText:'Pick group...', mode:'remote', anchor:'95%', allowBlank:false, enableKeyEvents:true, triggerAction:'all', forceSelection:true
, listeners:{keypress:{scope:this, fn:function(fld,e){ if(e.getKey()==e.ENTER) doLogin();}}
}}
]
});
服务器返回的json数据:
{"entities":[{"@type":"webGroup","groupId":"1","groupName":"TEST","groupUsers":
[{"groupUserId":"2","groupUserName":"FOO","password":"123456"},
{"groupUserId":"1","groupUserName":"FOO","password":"654321"}],"system":"BLA"},
{"@type":"webGroup","groupId":"2","groupName":"TESTOS","system":"BLA"}]
,"success":"true"}
PHP 代码:
function getGroups(){
error_log("API_host: ".$API_host, 0);
global $API_host;
error_log("API_host: ".$API_host, 0);
$url="$API_host/GroupUser/groups";
error_log("url: ".$url, 0);
$jsonData = curl_request($url);
if (!$jsonData) die("{success:false, message:'Connection Error'}");
echo $jsonData;
}
也许从 PHP 返回的数据不是 JSON 格式的?我怎么知道?我什么都不确定。
不明白为什么它不起作用。
有什么想法吗?
非常感谢。
【问题讨论】:
标签: php extjs combobox jsonstore