为什么ViewModel中声明的商店不能加载? [英] Why doesn't a store declared in a ViewModel get loaded?

查看:210
本文介绍了为什么ViewModel中声明的商店不能加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题与尝试将商店绑定到ViewModel有关,但是是一个不同的问题。

This question is related to Trying to bind a store to a ViewModel, but is a different question.

我正在这样一个viewmodel中声明一个商店:

I'm declaring a store in a viewmodel like this:

Ext.define('Mb.view.rma.DetailsModel', {
    extend: 'Ext.app.ViewModel',
    alias: 'viewmodel.rma-details',
    requires: ['Mb.model.rma.Detail'],
    data: {
        id: 0
    },
    stores:{
        details: {
            //store: 'rma.Details',
            type: 'rmaDetails', // correction as suggested by @scebotari
            filters: [{
                property: 'rma',
                value: '{id}'
            }],
            remoteFilter: true
        }
    }
});

当我实例化视图时,值 id 在viewmodel中正确更新(我可以看到这一点,因为View通过绑定标题反映出来):

When I instantiate the view, the value id is correctly updated in the viewmodel (I can see this because the View reflects it through the bound title):

Ext.define('Mb.view.rma.Details', {
    extend: 'Ext.grid.Panel',
    requires: [
        'Mb.view.rma.DetailsModel'
    ],
    viewModel: {
        type: 'rma-details'
    },
    bind: {
        title: 'Retour n° {id}',
        store: '{details}'
    },

我面临的问题即使在viewmodel中设置了 remoteFilter:true 属性(设置 remoteFilter:true 在商店类中而不是viewmodel不会改变行为)。

The problem I'm facing is that the store does not get loaded, even though there is the remoteFilter: true property in the viewmodel (setting remoteFilter: true in the store class instead of the viewmodel does not change the behavior).

要完成代码,这里是商店(没有什么特别的):

To complete the code, here is the store (nothing special):

Ext.define('Mb.store.rma.Details', {
    extend: 'Ext.data.Store',
    model: 'Mb.model.rma.Detail',
    alias: 'rmaDetails', // correction as suggested by @scebotari
    proxy: {
        (...)
    },
    remoteFilter: true
});

主要问题:为什么商店不能加载?

附属问题:像一个发票的行一样显示一个细节网格是一个常见的问题。我不知道我正在尝试的是使用MVVM推荐的方法来解决这个问题。 MVVM似乎比MVC更好,因为它可以一次打开多个详细信息实例。我没有找到这个例子。有没有一个推荐的方法来解决这个问题?

Subsidiary question: It looks as a frequent problem to show a details grid like the lines of an invoice for instance. I'm not sure if what I'm trying is the recommended approach using MVVM for this problem. MVVM seems better than MVC, because it gives the possibility to open more than one details instance at a time. I didn't find an example for this case. Is there a recommended way to solve this problem ?

注意:

过滤器应用应用。

商店 {details} 似乎不是一个链接的商店。事实上,当将 store:'rma.Details'更改为 source:'rma.Details'在viewmodel中。

The store {details} doesn't seem to be a chained store. In fact, it becomes a chained store when changing store: 'rma.Details' into source: 'rma.Details' in the viewmodel.

推荐答案

据我所知,这不是你如何使用在单独的类中声明的商店视图模型。

As far as I am aware, this is not how you use stores declared in separate classes in the viewmodels.

当声明在视图模型中使用的商店时,应该如下指定别名配置:

When declaring a store that you want to use in a view model, you should specify the "alias" config like so:

Ext.define('Mb.store.rma.Details', {
    extend: 'Ext.data.Store',
    model: 'Mb.model.rma.Detail',
    alias: 'store.rmaDetails',
    proxy: {
        (...)
    }
});

然后在type存储配置中的viewmodel中使用此别名:

And then use this alias in the viewmodel in the "type" store config:

stores:{
    details: {
        type: 'rmaDetails',
        filters: [{
            property: 'rma',
            value: '{id}'
        }],
        remoteFilter: true,
        autoLoad: true
    }
}

我不知道为什么还没有记录。也许是因为以后添加了此功能( https: //www.sencha.com/forum/showthread.php?284012-Use-existing-Store-in-ViewModel )。

I don't know why this is not documented yet. Maybe because this capability was added later (https://www.sencha.com/forum/showthread.php?284012-Use-existing-Store-in-ViewModel).

数据将加载自动设置 autoLoad:true 。该视图模型中的商店配置扩展了商店类 store.rmaDetails 。每个视图实例都有自己的存储实例关联(这与默认实例 .getStore('rma.Details')不同。

The data will load automatically when setting autoLoad: true. The store configs in the viewmodel extend the store class store.rmaDetails. Each view instance has its own store instance associated (that is different from the default instance .getStore('rma.Details').

这篇关于为什么ViewModel中声明的商店不能加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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