Extjs在ViewModel中将商店链接到GlobalStore

时间:2022-06-16 04:35:13

I want to use a store that in chained to global store, but after launch I gives js warning:

我想使用一个链接到全球商店的商店,但在发布后我给js警告:

Ext.data.Store created with no model

and i cannot see any data.

我看不到任何数据。

Here is my code:

这是我的代码:

Global UserStore

Ext.define('App.store.UserStore',{
extend      : 'App.store.AjaxReadyStore',
requires    : ['App.model.UserModel'],
model       : 'App.model.UserModel',
autoLoad    : false,
id          : 'UserStore',
alias       : 'store.UserStore',


constructor : function() {
    this.callParent(arguments);
    this.proxy.api= {
        create  : 'api/v1/users',
        read    : 'api/v1/users',
        update  : 'api/v1/users',
        destroy : 'api/v1/users'
    };
    this.readAndLoad();
}
});

ViewModel

Ext.define('App.view.tasktemplate.TaskTemplateModel', {
    extend  : 'Ext.app.ViewModel',
    alias   : 'viewmodel.tasktemplate',
    stores : {
        owner: {
            source  : 'UserStore'
        }
    }
});

View

Ext.define('App.view.tasktemplate.TaskTemplateOwnerList',{
    extend  : 'App.view.pool.grid.GridWithAction',
    xtype   : 'tasktemplateownerlist',
    store: {
        bind : '{owner}'
    },
});

1 个解决方案

#1


Change your view code to this -

将您的观看代码更改为此 -

Ext.define('App.view.tasktemplate.TaskTemplateOwnerList',{
        extend  : 'App.view.pool.grid.GridWithAction',
        xtype   : 'tasktemplateownerlist',
        bind: {
            store : '{owner}'
        }
    });

Store Binding:

bind: {
     store : '{owner}'
}

It's actually interesting when you do

当你这样做时,它真的很有趣

store: {
        bind : '{owner}'
    }

inside your view - The StoreManager does a lookup with the value of the store config, usually expecting a string or array of strings (store name) but it sees that it's not a string but an object so it creates a instance of 'Ext.data.Store' passing {bind:'{owner}'} as config -> so you actually get an instance of the Store class with no models associated. store:

在你的视图中 - StoreManager使用商店配置的值进行查找,通常期望字符串或字符串数​​组(商店名称),但它看到它不是字符串而是对象,因此它创建了一个'Ext.data的实例.Store'传递{bind:'{owner}'}作为配置 - >所以你实际上得到了没有关联模型的Store类的实例。商店:

#1


Change your view code to this -

将您的观看代码更改为此 -

Ext.define('App.view.tasktemplate.TaskTemplateOwnerList',{
        extend  : 'App.view.pool.grid.GridWithAction',
        xtype   : 'tasktemplateownerlist',
        bind: {
            store : '{owner}'
        }
    });

Store Binding:

bind: {
     store : '{owner}'
}

It's actually interesting when you do

当你这样做时,它真的很有趣

store: {
        bind : '{owner}'
    }

inside your view - The StoreManager does a lookup with the value of the store config, usually expecting a string or array of strings (store name) but it sees that it's not a string but an object so it creates a instance of 'Ext.data.Store' passing {bind:'{owner}'} as config -> so you actually get an instance of the Store class with no models associated. store:

在你的视图中 - StoreManager使用商店配置的值进行查找,通常期望字符串或字符串数​​组(商店名称),但它看到它不是字符串而是对象,因此它创建了一个'Ext.data的实例.Store'传递{bind:'{owner}'}作为配置 - >所以你实际上得到了没有关联模型的Store类的实例。商店: