如何使用Sencha Touch 2框架的代理拥有多个CRUD方法



我使用Sencha Touch 2框架编写了一个小型移动应用程序。目前,我从本地主机的数据库管理一些文章。我使用ArticleService.php文件中包含的PHP CRUD方法编写了一个数据库管理程序。我的"阅读"函数返回所有的文章。但我想有一个其他的"阅读"方法来阅读,例如根据它的id或最近的5篇文章,等等。但是store代理(我认为是这样)允许每个主要操作有1个方法。所以在我的例子中,对于'read'操作,我只有一个'read'方法。

这是我的'store'源代码:

Ext.define("MyApp.store.ArticleStore", {
    extend: "Ext.data.Store",
    requires: ["MyApp.model.ArticleModel"],
    config: {
    model: "MyApp.model.ArticleModel",
    proxy: {
        type: "ajax",
        api: {
            create: "http://localhost/MobileApplication/MyApp/services/ArticleService.php?action=create",
            read: "http://localhost/MobileApplication/MyApp/services/ArticleService.php?action=read",
            update: "http://localhost/MobileApplication/MyApp/services/ArticleService.php?action=update",
            destroy: "http://localhost/MobileApplication/MyApp/services/ArticleService.php?action=destroy"
        },
         extraParams: {
            keyword: ""
        },
        reader: {
            type: "json",
            rootProperty: "articles",
            totalProperty: "total"
        }
    },
        autoLoad: true
    }
});

是否有一种可能的方法来为每个主要的CRUD操作有几个方法(例如3个不同的'read'方法来管理我的文章显示)?我真的迷路了。提前感谢您的帮助!

您不需要不同的方法来读取。一旦你加载存储,它将在内存中,你将能够找到任何你想要的记录。

如果你的存储太大,不能一次加载-看看remoteFilter属性:http://docs.sencha.com/touch/2.1.1/#!/api/Ext.data.Store-cfg-remoteFilter这种方式过滤器你将设置(如id = 1或parent_id = 2)将被传递到服务器,所以它可以返回适当的记录集。

最新更新