欢迎访问中国最大的EXTJS讨论社区 首页 论坛 教程

Ext教程-一起Ext

当前位置: 首页 > 教程 > Ext Data Store >

Ext.sql.SQLiteStore从dataview加载数据

时间:2009-05-03 21:56来源:未知 作者:admin 点击:
在用Ext.sql.SQLiteStore开发一个Air应用的时候,有这样一个需求:从数据库的一个视图(view)获取数据(不是从普通的数据表),于是指定了表名属性为视图的名字,代码如下: var grid =

  在用Ext.sql.SQLiteStore开发一个Air应用的时候,有这样一个需求:从数据库的一个视图(view)获取数据(不是从普通的数据表),于是指定了表名属性为视图的名字,代码如下:
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/)所有,转载请注明出处
顶一下
(3)
100%
踩一下
(0)
0%
------分隔线----------------------------
最新评论 查看所有评论
发表评论 查看所有评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 密码: 验证码:
推荐内容