How can I handle several store instance in the sam

2019-09-09 04:35发布

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

Here's a view of my home page :

enter image description here

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 :

enter image description here

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.

1条回答
萌系小妹纸
2楼-- · 2019-09-09 04:41

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.

查看更多
登录 后发表回答