Rick Weller
Rick Weller

Reputation: 1258

one value from json in extjs

i use a store with a model. The jason has a value i want to use in an alert. The json is like this

{"slapen":[{"naam":"test","leeftijd":"43"},{"naam":"test2","leeftijd":"27"}]}

i want to display an alert for the first result. So when the store is loaded i want an alert like this

alert('De eerste winnaar is {here_comes_leeftijd} jaar');

so the number is what i want to show. Is this possible?

winnaars = new Ext.data.Store({
    model: 'stepDetails',
    pageSize: 20,
    loadMask: false,
    sortOnLoad: true,

    proxy: {
        type: 'ajax',
        url: detailURL,
        startParam: '',
        limitParam: '',
        pageParam: '',
        reader: {
            type: 'json',
            root: 'slaevents'
        }
    },
    autoLoad: false
});

Upvotes: 0

Views: 112

Answers (1)

Izhaki
Izhaki

Reputation: 23586

You can listen to the store's load event (either externally or by using the listeners config) and inspect the returned records there and act upon them.

winnaars = new Ext.data.Store({
    model: 'stepDetails',
    pageSize: 20,
    loadMask: false,
    sortOnLoad: true,

    proxy: {
        type: 'ajax',
        url: detailURL,
        startParam: '',
        limitParam: '',
        pageParam: '',
        reader: {
            type: 'json',
            root: 'slaevents'
        }
    },
    autoLoad: false


    listeners: {
        load: function( aStore, aRecords, aSuccess, aeOpt) {
            // Do something here.
            console.log(aRecords);
        }
    }
});

Upvotes: 1

Related Questions