我想使用jsonStore將json數據加載到我的組合框。 商店使用PHP從服務器檢索數據。ExtJs 4 - 與jsonstore的組合框保持爲空
我可以看到服務器正在處理PHP請求並響應正確的json數據,但不知何故組合框保持空白。
相關代碼:
商店和組合框 - 組合框裏面FormPanel中:
{"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代碼:
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數據:
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返回的數據?我怎麼知道它?我不確定任何事情。
不明白爲什麼它不起作用。
任何想法的人?
非常感謝。
不能明白你的意思。如果要組?並更改組名稱是什麼? – yanivsh
我的意思是說你的組合框中的'name'配置是'groups',而不是它們在json響應中。當設置時,repsonse根據組件的'name'配置映射。 – Dev
它沒有幫助。將'name'配置更改爲'groupName',並將其刪除。在這兩種情況下,結果都是相同的,組合框中沒有數據。'displayField'和'valueField'用於執行此操作映射? – yanivsh