-
16 Apr 2010 7:21 AM #1
Problems while using direct to fill a combobox
Problems while using direct to fill a combobox
Hi,
I have a combobox store:
if i call login.cmb_security_store.load , it loads the data.PHP Code:login.cmb_security_store = new Ext.data.DirectStore({
directFn:AcSrvService.getUserRoles,
paramsAsHash:false,
idProperty:'path',
root:'',
paramOrder: ['username'],
fields:[
{name:'displayname'},
{name:'path'}
],
listeners: {
beforeload: function(store, options){
if (Ext.getCmp('username').getValue().length != 0) {
options.params.username = Ext.getCmp('username').getValue();
}
else
return;
}
}
});
This is the response from my backend:
For some reason, I just have hte first entry in my combobox (Archivnutzung), the other 2 entrys won't appear.PHP Code:{"tid":3,"action":"AcSrvService","method":"getUserRoles","result":[{
"displayname":"Archivnutzung","path":"/SYSTEM/ROLES/ARCHIVE"},{
"displayname":"Datenerfassung","path":"/SYSTEM/ROLES/CAPTURE"},{
"displayname":"Administration","path":"/SYSTEM/ROLES/ADMIN"}],"type":
"rpc"}
Anyone knows why?
Christian
-
18 Apr 2010 1:50 AM #2
-
18 Apr 2010 8:53 PM #3
Are you sure the problem has anything to do with direct? What if you try and load it like:
Code:login.cmb_security_store = new Ext.data.JsonStore({ idProperty:'path', root:'', fields:[ {name:'displayname'}, {name:'path'} ], listeners: { beforeload: function(store, options){ if (Ext.getCmp('username').getValue().length != 0) { options.params.username = Ext.getCmp('username').getValue(); } else return; } }, data: [{ "displayname":"Archivnutzung","path":"/SYSTEM/ROLES/ARCHIVE"},{ "displayname":"Datenerfassung","path":"/SYSTEM/ROLES/CAPTURE"},{ "displayname":"Administration","path":"/SYSTEM/ROLES/ADMIN"}] });Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
19 Apr 2010 1:21 AM #4
Hi Evant,
even if I copy your code to try it with local data, I don't see any results in the combobox.
I've copied the combobox which I use, maybe I do something wrong in here:
and here's the store again. (I've changed it a bit, but still no luck.PHP Code:{
id : 'cmb_security',
xtype : 'combo',
bodyStyle : 'padding:10px',
layout : 'form',
store : login.cmb_security_store,
displayField : 'displayname',
valueField : 'path',
mode : 'local',
triggerAction : 'all',
typeAhead : true,
editable : false
(-...-)
JSON CODE from Server: (Jslint says it's ok..)PHP Code:login.cmb_security_store = new Ext.data.DirectStore({
directFn:AcSrvService.getUserRoles,
paramsAsHash:false,
autoLoad:true,
reader: new Ext.data.JsonReader({
root: 'data',
fields:[
{name:'displayname'},
{name:'path'}
],
}),
paramOrder: ['username'],
listeners: {
beforeload: function(store, options){
if (Ext.getCmp('username').getValue().length != 0) {
options.params.username = 'test';//Ext.getCmp('username').getValue();
login.cmb_security_store.removeAll()
Ext.getCmp("cmb_security").setValue("");
}
else
return;
},
load : function(ds,records,o){
console.log(ds,records,o);
if (records.length > 0) {
Ext.getCmp("cmb_security").setValue(records[0].data.path);
}
}
}
});
PHP Code:{"tid":2,"action":"AcSrvService","method":"getUserRoles","result":{"data":[{
"displayname":"Archivnutzung","path":"/SYSTEM/ROLES/ARCHIVE"},{
"displayname":"Datenerfassung","path":"/SYSTEM/ROLES/CAPTURE"},{
"displayname":"Administration","path":"/SYSTEM/ROLES/ADMIN"}],
"success":true},"type":"rpc"}
-
4 May 2010 12:20 AM #5
I think you need to return the data in a root key and maybe also return a totals field
My response from direct looks like this:
In the store you need to set the root config in my case:Code:{"type":"rpc","tid":2,"action":"user","method":"combo_query","result":{"total":3,"items":[{"id":1,"name":"XXX"},{"id":2,"name":"YYY"},{"id":3,"name":"ZZZ"}]}}
Code:root: 'items'


Reply With Quote
)