Javascript ExtJs存储未找到记录,但最近保存了一条记录
我正在与Sencha Touch和您可以找到的sqLite代理合作一个项目。此网站位于phonegap环境中,但在我从浏览器运行时未使用它 我有一个Javascript ExtJs存储未找到记录,但最近保存了一条记录,javascript,extjs,Javascript,Extjs,我正在与Sencha Touch和您可以找到的sqLite代理合作一个项目。此网站位于phonegap环境中,但在我从浏览器运行时未使用它 我有一个WorkShift模型,供WorkShift商店使用 型号: Ext.define('KCS.model.WorkShift', { extend: 'Ext.data.Model', config: { fields: [ { name: 'id', type: 'int' },
WorkShift
模型,供WorkShift
商店使用
型号:
Ext.define('KCS.model.WorkShift', {
extend: 'Ext.data.Model',
config: {
fields: [
{ name: 'id', type: 'int' },
{ name: 'WorkShiftID', type: 'int' },
{ name: 'StartDate', type: 'date' },
{ name: 'ClosureDate', type: 'date' },
],
proxy: {
type: 'sqlitestorage',
dbConfig: {
tablename: 'tbl_WorkShift',
dbConn: KCS.util.InitSQLite.getConnection()
}
}
}
});
Ext.define('KCS.store.WorkShifts', {
extend: 'Ext.data.Store',
requires: ['KCS.model.WorkShift'],
config: {
model: 'KCS.model.WorkShift',
autoLoad: true,
storeId: 'WorkShifts',
pageSize: 1000
}
});
而商店:
Ext.define('KCS.model.WorkShift', {
extend: 'Ext.data.Model',
config: {
fields: [
{ name: 'id', type: 'int' },
{ name: 'WorkShiftID', type: 'int' },
{ name: 'StartDate', type: 'date' },
{ name: 'ClosureDate', type: 'date' },
],
proxy: {
type: 'sqlitestorage',
dbConfig: {
tablename: 'tbl_WorkShift',
dbConn: KCS.util.InitSQLite.getConnection()
}
}
}
});
Ext.define('KCS.store.WorkShifts', {
extend: 'Ext.data.Store',
requires: ['KCS.model.WorkShift'],
config: {
model: 'KCS.model.WorkShift',
autoLoad: true,
storeId: 'WorkShifts',
pageSize: 1000
}
});
现在,在我的控制器中,我想看看是否有打开的工作档
(如果应用程序崩溃或在没有关闭最后一个工作档
的情况下关闭),因此我使用如下启动回调:
launch : function(){
var workShifts = Ext.getStore('WorkShifts');
workShifts.clearFilter(true);
var openedWS = workShifts.findBy( function( record ){
return (record.get("StartDate") != null) &&
(record.get("ClosureDate") == null);
});
if( openedWS != -1 ){
// do stuff when an opened WS is found
}
else{
// do normal stuff
}
},
我做了一系列测试,首先,sqLite中有一系列有效的条目,我可以从存储和模型中创建WS。还有一个条目符合bool测试的findBy。我尝试了workshift.getCount()
甚至workshift.getAllCount()
,但这两个函数都返回0。我做错了什么
编辑:
我还搜索了一些东西,比如在商店可以从代理加载数据之前运行的launch func,或者甚至在cordova不启动deviceReady回调之前运行的launch func。我曾尝试在存储上应用一个过滤器,并使用getFirst()
检查是否有一条记录通过了测试,但我认为,即使它们出现在资源选项卡(在chrome webTools中)的SqLite概览中,也没有一条记录需要测试.我使用了商店的手动加载功能,并使用回调来执行我需要的操作。存储创建中的autoload参数也是异步的。那是我的问题
像这样:
launch : function(){
var workShifts = Ext.getStore('WorkShifts');
workShifts.load({
callback: function(records, operation, success) {
workShifts.clearFilter(true);
var openedWS = workShifts.findBy( function( record ){
return (record.get("StartDate") != null) &&
(record.get("ClosureDate") == null);
});
if( openedWS != -1 ){
// do stuff when an opened WS is found
}
else{
// do normal stuff
}
},
scope: this
});
},