Вопрос

I'm trying to load json data to my combo box using jsonStore. The store is using PHP for retrieving the data from the sever.

I can see that the server is handling the PHP request and response with proper json data, but somehow the combobox stays empty.

Relevant code:

The store and the ComboBox - the ComboBox is inside 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();}}
         }}
    ]
});

The json data that returned from the server:

{"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"}

The PHP code:

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;
}

Maybe the data returned from the PHP formatted other than JSON? How can i know it? I'm not sure of anything.

Can't understand why it's not working.

Any ideas anyone?

Thanks so much.

Это было полезно?

Решение 2

OK. Found the problem.

It was with my php code.

The php file, beside the function 'getGroups', includes also a html page that loads the formPanel with the comboBox.

So whenever i try to load to store into the comboBox, it loads the entire html with the formPanel and the comboBox from scratch - whichs make my store data to disappear.

When i set the url of the store to other php file that include the same code but without the html block, the store loads it's data correctly and everything is working!

Silly me :(

Hope it will help someone in the future.

Другие советы

Their should be groups in your json response or change the combo name to groupName.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top