4

I'm using Sencha touch 2. I have store that load from 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 looking at Data view in Sencha touch i've added autoLoad and itemSelector, still no luck.

Though running

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

outputs list of objects with filled data attributes.

UPDATE

I agree with @fbrandel that first option is how it should work, but after reading ST source i've figured out that store parameter of dataview is interpreted as:

  • store object
  • json store notation like in first example here
  • name of already created store which can be resolved using StoreManager.lookup

So I ended up with:

  1. Leaving store:'Dataset' in View
  2. Adding storeId : "Dataset" to store, so it can be resolved by StoreManager
  3. Adding stores: ['Dataset'] which caused creation of majestic.store.Dataset and registering it in StoreManager

P.S. It also could be done using this.setStore(new majestic.store.Dataset()) in initialization method of GridView, but I prefer declarative way where posible

Community
  • 1
  • 1
Pavel Krymets
  • 6,253
  • 1
  • 22
  • 35

2 Answers2

2

Here are some suggestions:

  1. Try to set the store to 'majestic.store.Dataset' instead of just Dataset
  2. Add the store dependency to your app.js like this:

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

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

Option #1 seems to be the most obvious way how it should work. If it does not, this might be a bug in ST2.

fbrandel
  • 1,605
  • 3
  • 17
  • 18
0

Maybe your missing an id field

Anyway, I'm building in Architect with no luck as well, but seems a totally different problem. I'll follow the tutorial in Architect (building your first mobile app) and maybe get insight.

pashute
  • 3,965
  • 3
  • 38
  • 65