【发布时间】:2015-12-30 04:30:18
【问题描述】:
我在 Sencha Touch v2 控制器中有一段代码,如下所示。运行此代码时,store.add 后的计数为 (6),store.sync 后的计数器为 (0),store.sync 成功。
注意:项目包含从 JsonP 代理收到的 6 条记录,控制台中没有显示任何错误,并且一切都好像完全成功。
requires: [
'Ext.data.proxy.JsonP',
'Ext.data.proxy.Sql'
],
config: {
models: ['Convention'],
stores: ['Conventions']
},
// ***additional code*** //
store.setProxy({
type: 'sql',
database: 'app',
table: 'Conventions'
});
store.removeAll();
store.sync({
success: function(batch){
store.add(items);
console.log("Count before: " + store.getCount()); << Shows (6)
store.sync({
failure: function (batch, options) {
console.log('Convention Sql failure');
},
success: function(batch,options){
console.log("Count after: " + store.getCount()); << Shows (0)
console.log("Convention Sql success");
store.load();
Ext.Viewport.unmask();
}
});
}
});
模型显示在这里
extend: 'Ext.data.Model',
config: {
idProperty: 'id',
fields: [
{ name: 'id', type: 'string' },
{ name: 'name', type: 'string' },
{ name: 'logoId', type: 'string' },
{ name: 'seasonId', type: 'string'},
{ name: 'viewed', type: 'string'},
{ name: 'dateCreated', type: 'string'},
{ name: 'dateUpdated', type: 'string'}
]
}
商店就在这里
extend: 'Ext.data.Store',
requires: [
'Ext.data.proxy.Sql'
],
config: {
model: 'app.model.Convention',
autoLoad: false,
sorters:[{
property: 'name',
direction: 'ASC'
}],
proxy: {
type: 'sql',
database: 'app',
table: 'Conventions'
}
}
【问题讨论】:
-
深入挖掘,如果我从项目中删除 ID 并让模型执行自动 ID,它就可以工作。我只能假设我需要定义我的 ID。有什么建议吗?
标签: sencha-touch-2