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.
{ id: 1, sample: "some strings"}
but I don't see theid
andsample
fields in your model. Is that part of your design? – Guilherme Lopesid
meansmyId
, and thesample
now I change it tonumber
– icese7en