Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将存储别名放入视图层的extjs处理程序中_Extjs_Extjs Mvc - Fatal编程技术网

如何将存储别名放入视图层的extjs处理程序中

如何将存储别名放入视图层的extjs处理程序中,extjs,extjs-mvc,Extjs,Extjs Mvc,我是extjs新手,我正在尝试为extjs mvc编写一个示例。如果我在一个文件app.js中编写mvc,它可以正常工作,但是如果我分离到不同的文件(模型、视图和控制器),则数据正在填充,但eventlisteners不工作: 以下是我的商店: Ext.define('Crud.store.Product',{ extend: 'Ext.data.Store', alias:'widget.pStore', model: 'Crud.model.Product',

我是extjs新手,我正在尝试为extjs mvc编写一个示例。如果我在一个文件app.js中编写mvc,它可以正常工作,但是如果我分离到不同的文件(模型、视图和控制器),则数据正在填充,但eventlisteners不工作: 以下是我的商店:

Ext.define('Crud.store.Product',{
    extend: 'Ext.data.Store',
    alias:'widget.pStore',
    model: 'Crud.model.Product',  
    autoLoad: true,
    autoSync: true

});
问题就在js看来:

var rowEditing = Ext.create('Ext.grid.plugin.RowEditing');
Ext.define('Crud.view.Main',{
    extend: 'Ext.grid.Panel',
    renderTo: document.body,
    plugins: [rowEditing],
    width: 400,
    height: 300,
    frame: true,
    title: 'Products',
    alias:'pGrid',
    store: 'Product',
    columns: [{
            text: 'ID',
            width: 40,
            sortable: true,
            dataIndex: 'id'
        }, {
            text: 'Name',
            flex: 1,
            sortable: true,
            dataIndex: 'name',
            field: {
                xtype: 'textfield'
            }
        }, {
            header: 'Price',
            width: 80,
            sortable: true,
            dataIndex: 'price',
            field: {
                xtype: 'textfield'
            }
        }],
    dockedItems: [{
            xtype: 'toolbar',
            items: [{
                    text: 'Add',
                    iconCls: 'icon-add',
                    handler: function() {
                        // empty record
                        store.insert(0, new Product());
                        rowEditing.startEdit(0, 0);
                    }
                }, '-', {
                    text: 'Delete',
                    iconCls: 'icon-delete',
                    handler: function() {
                        var selection = grid.getView().getSelectionModel().getSelection()[0];
                        if (selection) {
                            store.remove(selection);
                        }
                    }
                }]
        }]
});
grid.getView().getSelectionModel().getSelection()[0]
中,表示未定义grid,而
store.insert中未定义store的情况相同

在单个js文件中,如果我像下面这样创建变量,它就可以正常工作

grid=Ext.create('Ext.grid.Panel',{
//view code
}

and store= Ext.create('Ext.data.Store',{
   //store code
}

您可以帮助我如何获取存储和网格对象吗?

您必须从单击的按钮(处理程序的第一个参数)转到网格,然后从那里转到存储:

handler: function(btn) {
    var grid = btn.up('grid'),
        store = grid.getStore();

您可以将storeId分配给商店,并通过其Id获取商店

创建存储时:

store= Ext.create('Crud.store.Product',{
   storeId: 'some-store-id'
}
在事件处理程序中:

handler: function() {
   var store = Ext.getStore('some-store-id'); 
}

我能够得到商店,但它抛出了错误UncaughtReferenceError:产品未定义,下面是我的模型`Ext.define('Crud.model.Product',{extend:'Ext.data.model',--}我得到了var Product=Ext.ModelManager.getModel('Crud.model.Product');store.insert(0,Product);它工作了您可以使用全名创建一个新模型:
new Crud.model.Product()
,或者您只需添加一个空对象并让存储自动将其转换为适当类型的模型:
store.add({});