4

When I load a store using for a treeview component using the

store: 'somestore'

which has the following setup:

Ext.define('App.store.AdminNavigationTree', {
    extend: 'Ext.data.TreeStore',
    model: 'App.model.AdminNavigationTree',
    storeId: 'AdminNavigationTree',
    headers: { 'Content-Type': 'application/json' },
    proxy: {
        type: 'ajax',
        url: settings.ApiUrl + '/View/AdminNavigation/?format=json',
        reader: {
            type: 'json',
            root: 'result',
        }
    },
    folderSort: true
});

The data loads ok.

When trying to call store.load with the following store with the aim of populating a form it does not!

Ext.define('App.store.PromotionCompany', {
    extend: 'Ext.data.Store',
    model: 'App.model.PromotionCompany',
    storeId: 'PromotionCompany',
    headers: { 'Content-Type': 'application/json' },
    proxy: {
        type: 'ajax',
        url: settings.ApiUrl + '/Model/PromotionCompany/?format=json',
        reader: {
            type: 'json',
            root: 'result',
        }
    }
});

I'm using ServiceStack for the API and both of those URLs have [EnableCors] set and indeed - when store.load is called with the following:

store.load({
    params: { id: pcid },
    callback: function (records, options, success) {
        //do something
    }
});

I can see the request coming into the API and returning the correct data!

Does anyone have any clue what the heck ExtJs might be doing here?

1 Answers1

1

From what I recall on my last ExtJs + ServiceStack project, TreeStore and Store expects different data structures.

  • Inspect the response object using Chrome Dev Tools or Firebug, perhaps it's a parsing problem. At the least, it'll help to get you closer to a solution.
  • Double check your JsonReader properties (on your store), I've been caught a couple times because I forgot to set the 'root' property on it.

EDIT 1: I looked up my code, the response is similar, only difference being the inclusion of additional info such as leaf: true, etc.). I also failed to notice you have already set your root property in the code sample.

hhandoko
  • 326
  • 3
  • 14
  • I had to remove the corrs attribute from the service! doesn't make any sense but there we go :) –  Aug 30 '13 at 07:20
  • So you've found a solution? Great! Make sure you post your answer as an 'Answer' and mark it as such. – hhandoko Aug 30 '13 at 07:40
  • Not sure if it's a bug in Service Stack - adding the enable cors attribute as well as the plugin might cause a conflict? Don't know. If I get time I'll make a reproducible test –  Aug 30 '13 at 08:06