Sencha Touch DataView does not display items from the store

I am using Sencha touch 2. I have memory loaded from an existing js object:

Ext.define('majestic.store.Dataset', { extend : 'Ext.data.Store', requires : [ 'majestic.model.Dataset', 'majestic.util.config.ConfigurationManager' ], config : { model : 'majestic.model.Dataset', type: 'memory', reader: 'json', autoLoad : true, proxy: { type: 'memory', reader: { type: 'json', rootProperty : 'datasets' } } }, constructor: function(config) { this.callParent(arguments); this.applyData(majestic.util.config.ConfigurationManager.getConfig()); } }); 

Model:

 Ext.define('majestic.model.Dataset', { extend : 'Ext.data.Model', config : { fields : [ 'title' ], associations: [ {type: 'hasMany', model: 'Layer', name: 'layers'} ] } }); 

And view:

 Ext.define('majestic.view.LayerList', { requires: ['majestic.store.Dataset'], extend: 'Ext.dataview.List', config:{ store: 'Dataset', itemTpl: '<div>{id} is {title}</div>', itemSelector: "div" } }); 

After viewing the data view in Sencha touch, I added autoLoad and itemSelector, but no luck.

Although it works

 new majestic.store.Dataset().each(function(i) {console.log(i)}); 

displays a list of objects with filled data attributes.

UPDATE

I agree with @fbrandel that the first option is how it should work, but after reading the ST source, I realized that the store dataview parameter is interpreted as:

  • save object
  • json store note as in the first example here
  • name of an already created repository that can be resolved using StoreManager.lookup

So, I ended up with:

  • store:'Dataset' exit store:'Dataset' in view
  • Adding storeId : "Dataset" to save, so it can be enabled by StoreManager
  • Adding stores: ['Dataset'] , which caused the creation of majestic.store.Dataset and registration with StoreManager

PS This can also be done using the this.setStore(new majestic.store.Dataset()) method in the initialization the GridView method, but I prefer the declarative way, where possible

+4
source share
2 answers

Here are some suggestions:

  • Try installing the repository in "majestic.store.Dataset" instead of a simple dataset
  • Add your store’s dependency to your app.js as follows:

     Ext.application({ name: 'majestic', stores: ['Dataset'], launch: function() { ... } }); 
  • Instead of passing the string to the store property, pass the instance:

     store: Ext.create('majestic.store.Dataset') 

Option number 1 seems to be the most obvious way of working. If this is not the case, it may be an error in ST2.

+2
source

Perhaps your lack of id field

In any case, I also build in the Architect, but this is a completely different problem. I will follow the tutorial in Architect (creating the first mobile application) and, possibly, get an idea.

0
source

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


All Articles