0

我有这样的代码,你可以测试here如何在财产更改后立即启动财产变更事件?

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

当我的属性更改事件改变假值为true在这个例子中,当我点击关闭真/假盒仅火灾。我希望事件(或其他事件)在更改值后立即触发。我怎样才能做到这一点?

回答

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