如何使用Sencha Touch 2在同一动作中处理多个商店实例? [英] How can I handle several store instance in the same action using Sencha Touch 2?

查看:139
本文介绍了如何使用Sencha Touch 2在同一动作中处理多个商店实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的主页的一个视图:





我也可以通过点击它来打开一个特定的文章,并在其他视图中完整描述。



这是我的文章视图页面的具体文章: / p>



为了做到这一点,我在ArticleController类中应用一个过滤器(这里我得到匹配的记录)。

  onViewArticle:function(record){
var articleStore = Ext.getStore(ArticleStore);
var selectedArticle = record;
articleStore.filterBy(function(record,id){
if(selectedArticle.data.id == id)
return(true);
return(false);
});
Ext.Viewport.animateActiveItem(this.getArticleViewConnexContainer(),{
type:slide,direction:left
});
},

这里是我的商店类:

  Ext.define(MyApp.store.ArticleStore,{
extends:Ext.data.Store,
require:[ MyApp.model.ArticleModel]
config:{
model:MyApp.model.ArticleModel,
proxy:{
type:ajax,
api:{
create:http://localhost/MobileApplication/MyApp/services/ArticleService.php?action = create,
读取: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:{
关键字:
},
reader:{
type:json,
rootProperty:articles,
totalProperty:total
}
},
autoLoad:true
}
});

但现在,我想在同一个操作中应用另一个过滤器列出其他文章过滤器)在文章描述之下。这涉及到使用两种不同的过滤器,我想(有一个可以得到具体的文章(已经在这里完成),另一个我想要的文章列表中的文章列表)。但是我该怎么做呢?如果在同一个控制器功能中应用两个过滤器,则第二个过滤器会破坏防止一个,因为所有存储数据都在缓存中。有没有可能的方法(例如在PHP的MVC框架中)将变量从控制器发送到视图并显示其内容(通过这种方式,我将有两个不同的变量,我可以显示我的两个请求的内容我的看法)?或者可能在同一时间处理几家商店?我真的迷路了有人可以帮我吗感谢您的帮助。

解决方案

里面有几个问题。



Sencha框架是以一个商店 - 一个视图的概念构建的。因此,如果您有两个不同的视图来呈现来自真正一个数据存储的信息,那么您仍然需要拥有该商店的两个副本。如果您不需要同时显示这两个视图,则可以清除/应用后台过滤器(在手机应用程序中大多数情况下),但我建议使用两个单独的副本。



就您的情况而言 - 我不认为您需要这样做。当您显示特定的书籍时,您不需要过滤商店。您只需加载一个记录( store.getAt()),然后在您的子表单中使用此记录。


I coded a simple application which displays a dataview.List articles in the home page.

Here's a view of my home page :

I can also open a specific article by clicking on it and have its complete description in an other view.

Here's my article view page for a specific article :

To do this I apply a filter in my ArticleController class (here I get the matched record).

onViewArticle: function(record) {
        var articleStore = Ext.getStore("ArticleStore");
        var selectedArticle = record;
        articleStore.filterBy(function(record, id) {
            if (selectedArticle.data.id == id)
                return (true);
            return (false);
        });
        Ext.Viewport.animateActiveItem(this.getArticleViewConnexContainer(), {
            type: "slide", direction: "left"
        });
    }, 

And here's my store class :

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
    }
});

But now, I want to apply another filter in the same action to list others articles (with another specific filter) just below the article description. This involve to use two differents filters I think (one to get back the specific article (already done here) and an other one for the article list I want just below the article description). But how can I do this ? If I apply two filters in the same controller function, the second one will destroy the prevent one because all store data are in the cache. Is there a possible way (like in php MVC frameworks for instance) to send a variable from the controller to the view and display its content (By this way I will have two differents variables and I will can display the content of my two requests on my view)? Or maybe a possible way to handle several stores in the same time ? I'm really lost. Does anyone can help me, please ? Thanks in advance for your help.

解决方案

There are actually couple questions inside.

Sencha Framework is built with "one store - one view" concept in mind. So if you have two different view presenting information from really one data store, you still would need to have two copies of this store. You can clear/apply back filters if you don't need to show these two views at the same time (it's mostly true in case of phone applications), but I would recommend to have two separate copies.

As far as your scenario - I don't think you need that. When you're displaying particular book you don't need to filter store. You need to just load one record (store.getAt()) and then use this record in your child form.

这篇关于如何使用Sencha Touch 2在同一动作中处理多个商店实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆