extjs:将存储中的变量传递给控制器

Extjs: Passing variable in store to controller

本文关键字:控制器 变量 存储 extjs      更新时间:2023-09-26

我有一个自定义视图对象,该对象是从 Extjs 中的数据存储呈现的:

Ext.define('MemOS.view.Shortcut', {
    extend: 'Ext.view.View',
    alias: 'widget.shortcut',
    name: 'shortcut',
    singleSelect: true,
    store: 'Apps',
    tpl: [
        '<tpl for=".">',
            '<div id="iconGroup" class="icon-wrap">',
                '<div id="icon" class="icon">',
                    '<img src="/images/icons/" />',
                '</div>',
                '<span> {appName} </span>',
            '</div>',
        '</tpl>'
    ],  
    itemSelector: 'div.icon',
    plugins: [
        Ext.create('Ext.ux.DataView.DragSelector', {}),
        //Ext.create('Ext.ux.DataView.Draggable', {})
    ],
});

我还有一个控制器,其中包含双击商店中的商品时调用的事件:

Ext.define('MemOS.controller.Shortcut', {
    extend: ('Ext.app.Controller'),
    stores: ['Apps'],
    views: ['Shortcut'],
    ref: [{
            ref: 'shortcut-one',
            selection: '',
            xtype: 'shortcut',
            autoCreate: true        
    }],
    init: function(){
        this.control({
            'shortcut': {
                itemdblclick: function(d, i, n, e) {
                    console.log('Display Value From Data Store Here');
                }
            }
        });
    },
}); 

我要做的是将单击的项的数据存储值传递给控制器,以便我可以在警报框中显示相应的值。我的目标是稍后使用它根据用户单击打开特定的窗口/应用程序。

谁能帮我解决这个问题?谢谢。

同样,信息在文档中:

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.view.View-event-itemdblclick

传递的第二个参数是记录,因此您可以使用 record.get() 访问记录中的任何值

itemdblclick: function(view, record) {
    console.log(record.get('nameOfField'));
}