【问题标题】:Extjs: Passing variable in store to controllerExtjs:将存储中的变量传递给控制器
【发布时间】:2012-07-07 10:22:07
【问题描述】:

我有一个从 Extjs 中的数据存储区呈现的自定义 View 对象:

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');
                }
            }
        });
    },
}); 

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

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

【问题讨论】:

    标签: javascript extjs datastore


    【解决方案1】:

    同样,信息在文档中:

    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'));
    }
    

    【讨论】:

    • 对不起,我对编程比较陌生,并且试图通过这个来混淆我的方式。我已阅读文档,但不知道如何访问我需要的特定字段或值。
    • 更新了代码示例。如果您是编程新手,那么您将度过一段非常艰难的时期。
    • 谢谢。为什么你认为我会过得很艰难?
    猜你喜欢
    • 2017-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多