0
votes

How can I set the model's idProperty manually?
For example:
Assume that the idProperty of model is id
There is one record:
This is my Model:

Ext.define('MyApp.model.DataModel', {
extend: 'Ext.data.Model',

    config: {
        idProperty:'myId',
        fields: [
          { name: 'myId', type: 'auto' },
          { name: 'number', type: 'int' }
       ]
  }
});

This is my Store:

Ext.define('MyApp.store.DataStore', {
 extend: 'Ext.data.Store',
    config: {
      model: 'MyApp.model.DataModel',
      autoLoad: true,

      proxy: {
          type: 'localstorage',
          id: 'datastore'
       }
  }
});

With the code above, when I add one record like:

var store = Ext.getStore("DataStore");
var code = { myId: 1, number: 233 }
store.add(code);// The record added to the store.data, when I saw it in the developer tools
store.sync();  // yes, there is no error, but also without any change to this store  

How can I set this error? Because I see it's an bug in localstorage in Sencha Forum Bug source in 2012, I thought it would be fixed now.

---

And there is one other problem is:
The content of list is depend on the store it uses.
There is one list I use DataStore, Its code:

Ext.define('MyApp.view.SlideView', {
    extend: 'Ext.List',
    xtype: 'slideview',
    config: {
        itemTpl: Utils.Config.Templates,
        store: 'DataStore',
        layout: {
            type: 'fit',
            pack: 'right'
        },
        disableSelection: true,
        items: [
            {
                xtype: 'listitem',
                items: {
                    xtype:'panel',
                    tpl: Utils.Config.Templates,
                    data: Utils.Config.Templates.data,
                },
                minHeight: 60
            }
        ]
    }
});  

How can set this xtype (now it's listitem) like other items which introduce by the store record?
Because no matter the style or event, they are not same.

1
You are adding { id: 1, sample: "some strings"} but I don't see the id and sample fields in your model. Is that part of your design?Guilherme Lopes
@GuilhermeLopes I'm sorry, the id means myId, and the sample now I change it to numbericese7en

1 Answers

0
votes

If you set idProperty and you do not create your own implementation of how to use it, Sencha might use uuids. But as you are adding your own, I am not sure if this should be supported. Leave it to Sencha to add values to the idProperty key.

To grab the first item from a store simply use

var firstItem Ext.getStore('myStore').first(),
    data = firstItem.getData();

or in case you add the store to the list filter it to only the first item .... So many ways :)

To find out more about listitems please refer to the documentation. If you need to set the listitem to another xtype you can set

defaultType: 'newXtypeToUse'

Usually this will be 'simplelistitem' or 'listitem'