View Full Version : Problems while using direct to fill a combobox
chrizmaster
16 Apr 2010, 7:21 AM
Hi,
I have a combobox store:
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;
}
}
});
if i call login.cmb_security_store.load , it loads the data.
This is the response from my backend:
{"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"}
For some reason, I just have hte first entry in my combobox (Archivnutzung), the other 2 entrys won't appear.
Anyone knows why?
Christian
chrizmaster
18 Apr 2010, 1:50 AM
is this problem really that difficult or why is nobody there who has a little hint for me? (i don't request a solution, just a little hint..;) )
evant
18 Apr 2010, 8:53 PM
Are you sure the problem has anything to do with direct? What if you try and load it like:
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"}]
});
chrizmaster
19 Apr 2010, 1:21 AM
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:
{
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
(-...-)
and here's the store again. (I've changed it a bit, but still no luck.
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);
}
}
}
});
JSON CODE from Server: (Jslint says it's ok..)
{"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"}
macke
4 May 2010, 12:20 AM
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:
{"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"}]}}In the store you need to set the root config in my case:
root: 'items'
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.