extjs应用程序的多个实例

时间:2014-10-03 09:08:30

标签: javascript php extjs extjs-mvc extjs5

上下文

我目前正在制作管理用户的应用程序。我有一个PHP网站,我试图实现extjs。
由于我希望我的应用程序在我的php页面上的某些按钮被点击时启动,我使用request.prependBaseUrl = true;中的“bootstrap.js@load()”行,以便能够在我想要的任何页面上加载我的应用程序。

通过尝试和错误,我发现了一个主要问题,我现在已经遇到过几次了。在创建应用程序的多个实例时(例如,管理具有粗略功能的用户的窗口),我会收到应用程序已存在的错误。因此,对我的商店和控制器的引用只会改变,从而产生具有公共存储和控制器的2个“应用程序”。
这导致了令人讨厌的问题,例如当有2个应用程序时,控制器中的函数被调用两次,或者当我在第一个应用程序中对网格进行排序时,它也会在另一个应用程序中对其进行排序。

有没有办法让应用程序知道它需要启动自己的控制器等,这样当启动同一个应用程序的另一个实例时,它不会使用相同的控制器和存储?

此外,这里是我到目前为止的一些示例代码:

app.js

Ext.application({

    name: 'UserApplication',
    appProperty: '',
    stores: [
        'Users'
    ],
    views: [
        'Grid',
        'Delete',
        'Create',
        'Read',
        'Update'
    ],
    models: [
        'User'
    ],
    controllers: [
        'GridController'
    ],

    launch: function () {
        Ext.widget('usergrid');
    }
});

的GridView:

Ext.define("UserApplication.view.Grid",{
extend: 'Ext.window.Window',
xtype: 'usergrid',

title: 'Users',
autoShow: true,
width: 500,
height: 500,

layout: 'fit',

items: [{
    xtype: 'grid',
    border: false,
    frame: false,
    store: 'Users'
    columns: [
        { text: 'Name',  dataIndex: 'name', flex: 1},
        { text: 'Email', dataIndex: 'email', flex: 1},
        { text: 'Gender', dataIndex: 'gender', flex: 1}
    ]
}]});

Userstore:

Ext.define('UserApplication.store.Users', {
extend: 'Ext.data.Store',

requires: [
    'UserApplication.model.User'
],

//storeId: 'Users',
model: 'UserApplication.model.User',
proxy: {
    type: 'ajax',
    url: '/workspace/php/get_all.php'
},
autoLoad: true})
  

的usermodel:

Ext.define('UserApplication.model.User', {
extend: 'Ext.data.Model',
fields: [
    {name: 'name',  type: 'string'},
    {name: 'email',   type: 'string'},
    {name: 'gender',  type: 'int'}
]});

Gridcontroller:

Ext.define('UserApplication.controller.GridController', {
extend: 'Ext.app.Controller',

init: function(){
    this.control({
        'grid': {
            select: this.handleSelected
        }
    });
},

handleSelected: function(grid, record, index, eOpts){
    alert('test');
}});

0 个答案:

没有答案