有人可以告诉我如何在Sencha Touch中使用数据库吗?
请提出一些代码或示例。
谢谢
看看Ext.data.Store http://docs.sencha.com/touch/2.2.1/#!/api/Ext.data.Store
您不能直接使用数据库,而必须在前端和后端(服务器端或客户端后端,如HTML5 Webstorage)之间实现此层。
链接的sencha文档的客户端示例:
// Set up a model to use in our Store
Ext.define("User", {
extend: "Ext.data.Model",
config: {
fields: [
{name: "firstName", type: "string"},
{name: "lastName", type: "string"},
{name: "age", type: "int"},
{name: "eyeColor", type: "string"}
]
}
});
var myStore = Ext.create("Ext.data.Store", {
model: "User",
proxy: {
type: "ajax",
url : "/users.json",
reader: {
type: "json",
rootProperty: "users"
}
},
autoLoad: true
});
Ext.create("Ext.List", {
fullscreen: true,
store: myStore,
itemTpl: "{lastName}, {firstName} ({age})"
});
服务器端取决于您的环境。如果您使用基于服务器的后端,请以您选择的编程语言实现REST API。
为了将数据存储在本地设备/浏览器上,您必须实现LocalStorage代理。http://docs.sencha.com/touch/2.2.1/#!/api/Ext.data.proxy.LocalStorage
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句