PDA

View Full Version : Store in a function



Madiyana
14 Nov 2012, 3:28 AM
Hi,
I am a new user in ExtJS4 and I have a problem that i can't resolve..
I wanna put in a function this code :


var storeLD01_Objet = Ext.create('Ext.data.Store', {
fields :['id', 'libelle'],
labelWidth :150,
proxy: {
type: 'ajax',
url: '/value/TypeAmenrecherche/search',
reader: {
type: 'json',
root: 'elt'
}
},
listeners: {
'load': function(store, operation, options){
this.insert(0, {id:'--', libelle:'--'});
}
},
autoLoad: true
});


My objective is to have a function like :
function loadstore(link){
...
url: '/gtrte/link/search',
...
} because I want have a dynamic store who change with my value "link"

James Goddard
14 Nov 2012, 6:04 AM
loadstore: function (link) {
this.getProxy ().url = 'foo' + link + 'bar';
this.load ();
}

Madiyana
14 Nov 2012, 6:16 AM
Thank's.. It'is work now but when i used i can't do a selection in my combobox and i don't know why ..


var LD00_Nature = Ext.create('Ext.form.ComboBox', {
id :'nature',
fieldLabel :'Nature',
labelWidth :80,
store: storeLD00_Nature,
queryMode :'remote',
displayField :'libelle',
valueField :'libelle',
emptyText :'--',
editable :false,
listeners : {
select : function(liste, index){
if(liste.value=='Amenagement'){
storeLD01_Objet.getProxy ().url = '/gedeo/TypeAmenagement/recherche/',
storeLD01_Objet.load ();
}
if(liste.value=='Milieu'){
storeLD01_Objet.getProxy ().url = '/gedeo/TypeMilieu/recherche/',
storeLD01_Objet.load ();
}
}
},
border: 1
});


var storeLD01_Objet = Ext.create('Ext.data.Store', {
fields :['id', 'libelle'],
labelWidth :150,
proxy: {
type: 'ajax',
reader: {
type: 'json',
root: 'elt'
}
},
listeners: {
'load': function(store, operation, options){
this.insert(0, {id:'--', libelle:'--'});
}
},
autoLoad: true
});




Can you tell me the problem please?
Thank you very much

Madiyana
14 Nov 2012, 6:19 AM
Oups its Oki now...
I have forgot to add
url = '' in my Store..
Thank u for ur help

James Goddard
14 Nov 2012, 6:21 AM
Is storeLD01_Objet a global variable? You are not providing any scope to the object.

Madiyana
14 Nov 2012, 6:32 AM
Yes it is a global variable