var grid = Ext.grid.GridPanel({
...
store: Ext.sql.SQLiteStore({
autoLoad: true,
dbFile: 'db/database.sqlite',
tableName: 'vfiles',
key: 'fle_id',
fields: [
...
]
});
...
});
问题出现了:“'cannot modify 'vfiles' because it is a view', operation: 'execute', detailId: 2089 ”
但是数据还是显示出来了,我想这应该是一个bug ?
经过研究我override了一些代码,本文首发一起Ext http://www.17ext.com:
Ext.namespace('Ext.ux');
Ext.override(Ext.sql.AirConnection, {
getView: function(name){
return new Ext.ux.SQLiteView(this, name);
}
});
Ext.ux.SQLiteView = Ext.extend(Ext.sql.Table, {
constructor: function(conn, name) {
this.conn = conn;
this.name = name;
},
update: Ext.emptyFn,
updateBy: Ext.emptyFn,
insert: Ext.emptyFn,
lookup: Ext.emptyFn,
exists: Ext.emptyFn,
save: Ext.emptyFn,
remove: Ext.emptyFn,
removyBy: Ext.emptyFn
});
Ext.ux.SQLiteProxy = Ext.extend(Ext.sql.Proxy, {
constructor: function(conn, table, store, readonly){
Ext.sql.Proxy.superclass.constructor.call(this);
this.conn = conn;
this.table = table;
this.store = store;
if (readonly !== true) {
this.store.on('add', this.onAdd, this);
this.store.on('update', this.onUpdate, this);
this.store.on('remove', this.onRemove, this);
}
}
});
Ext.ux.SQLiteStore = Ext.extend(Ext.data.Store, {
constructor: function(config) {
config = config || {};
config.reader = new Ext.data.JsonReader({
id: config.key,
fields: config.fields
});
if (!config.conn || config.dbFile) {
var conn = Ext.sql.Connection.getInstance();
conn.open(config.dbFile);
} else var conn = config.conn;
// Create the database table if it does
// not exist
if (!config.viewName) {
conn.createTable({
name: config.tableName,
key: config.key,
fields: config.reader.recordType.prototype.fields
});
var table = conn.getTable(config.tableName, config.key);
} else var table = conn.getView(config.viewName);
Ext.ux.SQLiteStore.superclass.constructor.call(this, config);
this.proxy = new Ext.ux.SQLiteProxy(conn, table, this, false);
}
});
使用方法:var ds = new Ext.ux.SQLiteStore({
conn: new Ext.sql.AirConnection({
db: 'myDbFile.sqlite'
}),
viewName: 'myView',
key: 'id',
fields: [
{name: 'id', type: 'int'},
...
]
});
或者:var ds = new Ext.ux.SQLiteStore({
dbFile: 'myDbFile.sqlite',
tableName: 'myTable',
key: 'id',
fields: [
{name: 'id', type: 'int'},
...
]
});
指定viewName和tableName都是OK的。
声明:本站教程文章版权为一起Ext(http://www.17ext.com/)所有,转载请注明出处