0

我有这段代码,你可以在这里测试:

Ext.application({
    name: 'Fiddle',

    launch: function() {
        Ext.create('Ext.grid.property.Grid', {
            id: "PROPERTIES",
            renderTo: Ext.getBody(),
            autoHeight: true,
            width: 300,
            viewConfig: {
                forceFit: true,
                scrollOffset: 2 // the grid will never have scrollbars
            },
            listeners: {
                propertychange: function(source, recordId, value, oldValue) {
                    alert("new Value=" + value);
                }
            },
            source: {
                "title": "My Object",
                "color": Ext.Date.parse('10/15/2006', 'm/d/Y'),
                "Available": false,
                "Version": 0.01,
                "Description": "A test object"
            }
        });
    }
});

当我在示例中将 false 值更改为 true 时,属性更改事件仅在我单击 true/false 框时触发。我希望在更改值后立即触发事件(或另一个事件)。我怎样才能做到这一点?

4

1 回答 1

1

这是它的工作方式,只有在关闭编辑器后,您的字段才会触发 propertychange 事件。

如果您真的想在编辑器关闭之前为每个字段更改值运行一个函数或执行其他操作,您将必须添加一个控制器并监听属性面板内每个字段的更改事件。以下是它的工作原理:

Ext.define('MyApp.controller.MyController', {
    extend: 'Ext.app.Controller',


    init: function() {
        this.control({
            'propertygrid field': {
                change: function(field, newValue, oldValue, eOpts){
                    console.log(field, newValue, oldValue);
                }
            }
        });
    }
});

Ext.application({
    name: 'MyApp',

    controllers : ['MyController'],
    launch: function() {
        Ext.create('Ext.grid.property.Grid', {
            id: "PROPERTIES",
            renderTo: Ext.getBody(),

            autoHeight: true,
            width: 300,
            viewConfig: {
                 forceFit: true,
                 scrollOffset: 2 // the grid will never have scrollbars
            },
            listeners: {
                propertychange: function(source, recordId, value, oldValue) {
                    alert("new Value=" + value);
                }
            },
            source: {
                "title": "My Object",
                "color": Ext.Date.parse('10/15/2006', 'm/d/Y'),
                "Available": false,
                "Version": 0.01,
                "Description": "A test object"
            }
        });
    }
});

这是一个带有演示的小提琴:https ://fiddle.sencha.com/#fiddle/bti

于 2014-10-16T16:48:51.643 回答