PDA

View Full Version : Ext JS empty ItemSelector when loaded automatically from a JSON response



hieu79vn
10 Jul 2012, 8:09 AM
Hi,

if I create a variable for store and load, the itemselector shows data

var st= Ext.create('Ext.data.JsonStore',
{
fields: [{name: 'profil_code', type: 'string'}, {name: 'profil_label',type: 'string'}],
autoLoad: true,
proxy:{
limitParam: undefined,
startParam: undefined,
paramName: undefined,
pageParam: undefined,
sortParam: undefined,
filterParam: undefined,
noCache:false,
type:'ajax',
method: 'POST',
url: 'abc',
reader:{
type:'json'
}
}
});

st.getProxy().extraParams.ThreadID = 111;
st.getProxy().extraParams.BpmID = 11111;
st.getProxy().extraParams.Option = 1;
st.load();


Ext.define('ItemSelectorUser',{
extend: 'Ext.ux.form.ItemSelector',
alias: 'widget.itemselectoruser',
anchor: '100%',
imagePath: '../ux/images/',
initComponent: function () {
Ext.apply(this, {
displayField: 'profil_label',
valueField: 'profil_code',
autoload: true,
delimiter:',',


store: st

});

this.callParent(arguments);
}

});


But if i load store in itemselector, because i dont want to use a particular variable for store

Ext.define('ItemSelectorUser',{
extend: 'Ext.ux.form.ItemSelector',
alias: 'widget.itemselectoruser',
anchor: '100%',
imagePath: '../ux/images/',
initComponent: function () {
Ext.apply(this, {
displayField: 'profil_label',
valueField: 'profil_code',
autoload: true,

store: Ext.create('Ext.data.JsonStore',
{
fields: [{name: 'profil_code', type: 'string'}, {name: 'profil_label',type: 'string'}],
autoLoad: true,
proxy:{
limitParam: undefined,
startParam: undefined,
paramName: undefined,
pageParam: undefined,
sortParam: undefined,
filterParam: undefined,
noCache:false,
type:'ajax',
method: 'POST',
url: 'abc',
reader:{
type:'json'
}
}
})

});

this.callParent(arguments);
}

and call load from a form
,

loadUserListForm: function(){
this.itemselectoruser.store.getProxy().extraParams.ThreadID = 111;
this.itemselectoruser.store.getProxy().extraParams.BpmID = 11111;
this.itemselectoruser.store.getProxy().extraParams.Option = 1;
this.itemselectoruser.store.load();
},
createItemSelectorUser: function(){
this.itemselectoruser = Ext.create('widget.itemselectoruser',{});
return this.itemselectoruser;
}

data is not shown. Can you help me?
Thanks

scottmartin
11 Jul 2012, 1:20 PM
What does your JSON response look like?

Scott.

hieu79vn
12 Jul 2012, 11:37 PM
Hi Scott

I looks like this
[ { "profil_code": "buyer", "profil_label": "Buyer" }, { "profil_code": "doc_controller", "profil_label": "Document controller" }, { "profil_code": "engineer", "profil_label": "Discipline Engineer" }, { "profil_code": "supplier;310", "profil_label": "[ABC]" } ]

Thanks

scottmartin
13 Jul 2012, 6:48 AM
There is no root assigned to your return

ex:
{ total: 4, data:[{ "profil_code": "buyer", "profil_label": "Buyer" }, { "profil_code": "doc_controller", "profil_label": "Document controller" }, { "profil_code": "engineer", "profil_label": "Discipline Engineer" }, { "profil_code": "supplier;310", "profil_label": "[ABC]" }]}

Scott.

hieu79vn
16 Jul 2012, 2:14 AM
Thanks Scott. I will try it

hieu79vn
16 Jul 2012, 4:51 AM
HI Scott,

Do the data must be in array? Can I use Json string for store?

scottmartin
16 Jul 2012, 6:28 AM
Yes. Data (root) is the array of items that in that 'section' that will be read for specified root.

Sctto

hieu79vn
16 Jul 2012, 6:33 AM
Hi Scott

I mean that the data must be in format of array 2 dimension like this

data: [[123,'One Hundred Twenty Three'], ['1', 'One'], ['2', 'Two'], ['3', 'Three'], ['4', 'Four'], ['5', 'Five'], ['6', 'Six'], ['7', 'Seven'], ['8', 'Eight'], ['9', 'Nine']], stype: 'json'Or I can use the traditionel json string for store
[ { "profil_code": "buyer", "profil_label": "Buyer" }, { "profil_code": "doc_controller", "profil_label": "Document controller" }, { "profil_code": "engineer", "profil_label": "Discipline Engineer" }, { "profil_code": "supplier;310", "profil_label": "[ABC]" } ]

With the root, can I set it to '' like root:'' in the reader?

Thank you

scottmartin
21 Jul 2012, 10:05 AM
You should use json ... so the following would have a root: 'data'



{
"total": 4,
"data": [
{
"profil_code": "buyer",
"profil_label": "Buyer"
},
{
"profil_code": "doc_controller",
"profil_label": "Document controller"
},
{
"profil_code": "engineer",
"profil_label": "Discipline Engineer"
},
{
"profil_code": "supplier;310",
"profil_label": "[ABC]"
}
]
}


Scott.

hieu79vn
23 Jul 2012, 1:48 AM
Thank you Scott
I ve used arraylist and it runs