PDA

View Full Version : How to use a JSON Store with the itemselector



marxan
21 Mar 2011, 8:11 AM
Hi,

I've just tried the example of the itemselector that works perfectly but when I try to replace the ArrayStore by a JsonStore, I can't retrieve my data...

Here's my code:


var ds = new Ext.data.JsonStore({
totalProperty: 'DATASET',
root: 'ROWS',
url: '../components/JSONPreferences.cfc',
baseParams:
{
method: 'GetReferences',
returnFormat: 'JSON',
},
fields: ['value','reference']

});


multiselects: [{
width: 250,
height: 200,
store: ds,
displayField: 'Reference',
valueField: 'Reference'
},

Does anyone have already done this kind of thing?

Thanks,

Marxan

fay
21 Mar 2011, 8:33 AM
You specifed the fieldname as 'reference', but set it as 'Reference' in your displayField. JavaScript is case-sensitive.

marxan
21 Mar 2011, 11:32 PM
Thanks for your answer but it doesn't solved the problem.

More info: in FireFox, I don't even see the JSON in firebug. It seems that my component is never called.

fay
22 Mar 2011, 3:01 AM
Have you autoLoad set to true, or are you calling ds.load()? If you're doing either of those, and nothing is being returned, then the issue is likely to be on your server.

marxan
22 Mar 2011, 5:41 AM
you are right, I forget to put the autoLoad, but even now when my Json store is created, nothing is displayed in the selector...

I've found another way to do it but it's not really well built as I created an ArrayStore with a cfloop...


var ds = new Ext.data.ArrayStore({
// data: [[123,'224758'],
// ['1', '221632'], ['2', '285609'], ['3', '284709'], ['4', '284569'], ['5', '257856'],
// ['6', '216100'], ['7', '248629'], ['8', '212008'], ['9', '215910']],
data:[<cfloop query="qGetProjectsReference">
<cfset i = i + 1>
[#qGetProjectsReference.PROJECT_REF#, '#qGetProjectsReference.PROJECT_REF#']<cfif qGetProjectsReference.RecordCount neq i>,</cfif>
</cfloop> ],
fields: ['value','text'],
sortInfo: {
field: 'value',
direction: 'ASC'
}

But I'm sure there's is a better way to do that! Still searching....