【问题标题】:How to use Database in Sencha Touch? [closed]如何在 Sencha Touch 中使用数据库? [关闭]
【发布时间】:2013-08-29 11:09:53
【问题描述】:

谁能告诉我如何在 Sencha Touch 中使用数据库?

请推荐一些代码或示例。

感谢

【问题讨论】:

    标签: extjs sencha-touch sencha-touch-2


    【解决方案1】:

    看看 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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-07
    • 1970-01-01
    • 2013-02-15
    • 1970-01-01
    • 2011-09-18
    • 1970-01-01
    • 2012-03-03
    相关资源
    最近更新 更多