Extjs store.load with identifier throws CORS error

When I load a repository using a tree component using

store: 'somestore' 

which has the following setting:

 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 }); 

Data is loading normally.

When you try to call store.load with the following repository in order to fill out the form, this is not so!

 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 use ServiceStack for the API, and both of these URLs are set to [EnableCors] and indeed when calling store.load with the following:

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

I see a request coming in to the API and returning the correct data!

Does anyone know what ExtJs can do here?

+4
source share
1 answer

From what I remember in my last project, ExtJs + ServiceStack, TreeStore, and Store expect different data structures.

  • Inspect the response object using Chrome Dev or Firebug tools, this may be a parsing issue. At the very least, it will help you get closer to the solution.
  • Double-check the properties of JsonReader (in your store), I was caught a couple of times because I forgot to set the "root" property on it .

EDIT 1: I looked at my code, the answer is similar, only the difference is the inclusion of additional information such as leaf: true, etc.). I also did not notice that you already set the root property in the sample code.

+1
source

Source: https://habr.com/ru/post/1499198/


All Articles