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
如何从ExtJS中的映射事件启动viewcontrol中的函数?_Extjs - Fatal编程技术网

如何从ExtJS中的映射事件启动viewcontrol中的函数?

如何从ExtJS中的映射事件启动viewcontrol中的函数?,extjs,Extjs,我有带openlayers地图的MVVM应用程序。 在地图上执行特定事件(如完成绘制)时,我希望触发extjs网格的“添加”事件 我已尝试使用访问viewcontroller MyApp.app.getController('itemsController')但我得到错误: 无法识别的类名/别名:App.controller.itemsController 如何调用网格项的viewcontroller方法或激发事件来开始向网格添加项 Ext.define('App.view.grids.

我有带openlayers地图的MVVM应用程序。 在地图上执行特定事件(如完成绘制)时,我希望触发extjs网格的“添加”事件

我已尝试使用访问viewcontroller
MyApp.app.getController('itemsController')
但我得到错误:

无法识别的类名/别名:App.controller.itemsController

如何调用网格项的viewcontroller方法或激发事件来开始向网格添加项

    Ext.define('App.view.grids.ItemsViewController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.itemsController',    
    onNewClick: function (button, evt) {        
        var newItem = Ext.create('App.model.items.Item', {
            id:'',
            name:''            
        });
        this.isNewRecord = true;
        this.newRecordId = newEvent.get('id');
        var grid = this.lookupReference('itemsgrid');
        grid.getStore().insert(0, newEvent);
        grid.getPlugin('itemsRowEditingPlugin').startEdit(newEvent);
    }
});
视图定义:

Ext.define('App.view.grids.ItemsGrid', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.items',
    xtype: 'itemsGrid',
    reference: 'items',
    requires: [
        'App.view.grids.ItemsViewController',
        'App.view.grids.ItemsViewModel2'
    ],
    viewModel: {
        type: 'itemsViewModel'
    },
    controller: 'itemsController',
    session: true,
    width: '100%',
    height: 500,
    layout: {
        type: 'vbox',
        align: 'stretch'
    },
    items: [
        {
            xtype: 'grid',
            itemId: 'itemsgrid',
            reference: 'itemsgrid',
            width: '100%',
            title: 'Items',
            flex: 5,
            height: 350,
            maxHeight: 350,
            scrollable: 'y',
            header: true,
            viewConfig: {
                stripeRows: true
            },            
            bind:{
             store: '{itemsStore}'
             },
            columns: [
                {
                    dataIndex: 'id',
                    text: 'id'
                    //,hidden: true
                },
                {
                    dataIndex: 'hours',
                    text: 'Hours',
                    editor: {
                        xtype: 'numberfield',
                        minValue: 1,
                        allowBlank: false
                    }
                },
                {
                    dataIndex: 'address',
                    text: 'Address',
                    flex: 1,
                    editor: {
                        xtype: 'textfield',
                        allowBlank: false
                    }
                },
                {
                    dataIndex: 'name',
                    text: 'Name',
                    flex: 1,
                    editor: {
                        xtype: 'textfield',
                        allowBlank: false
                    }
                }
            ],

            selType: 'rowmodel',
            plugins: [
                {
                    ptype: 'rowediting',
                    pluginId: 'itemsRowEditingPlugin',
                    clicksToEdit: 1
                }
            ]
        }]
});

尝试如下方式访问您的控制器:


Ext.ComponentQuery.query('itemsGrid')[0].getController()

也在此处发布视图定义。视图定义是什么意思?视图的代码。使用“我的视图代码”进行更新是否比将组件保留在全局变量中更好?是的。99.9999%的时候你不想要一个全局变量你部分正确,我不得不使用Ext.ComponentQuery.query('items')[0].getController();(查询items而不是itemsGrid)关于这一点,为什么不给别名:“widget.itemsGrid”并删除xtype?然后使用Ext.ComponentQuery.query('itemsgrid')[0].getController();定义主视图时,我使用xtype生成面板。。。我可以改用别名吗?