2017-09-01 123 views
0

我在窗體中有一個窗體。我需要將外部窗體中字段的隱藏屬性綁定到內部窗體中字段的已檢查狀態。我以爲我可以通過設置自定義的getter/setter,但不能完全確定結合做到這一點......這裏的想法:ExtJS自定義綁定

Sencha fiddle

回答

1

你可以做這樣的事情:

Ext.define('Test.InnerForm', { 
    extend: 'Ext.form.Panel', 
    xtype: 'innerform', 

    defaultListenerScope: true, 

    config: { 
     isFoo: false 
    }, 

    twoWayBindable: { 
     isFoo: true 
    }, 
    publishes: ['isFoo'], 

    items:[{ 
     xtype: 'checkbox', 
     fieldLabel:'cb', 
     listeners: { 
      change: 'onCheckChange' 
     } 
    }], 

    onCheckChange: function(box, checked) { 
     this.setIsFoo(checked); 
    } 
}); 

Ext.define('Test.OuterForm', { 
    extend: 'Ext.form.Panel', 
    xtype: 'outerform', 
    viewModel: true, 
    items:[{ 
     xtype:'innerform', 
     reference: 'innerform' 
    },{ 
     xtype: 'textfield', 
     fieldLabel: 'want to hide this when cb is checked', 
     bind: { 
      hidden: '{innerform.isFoo}' 
     } 
    }] 
}); 


Ext.create('Test.OuterForm', { 
    title: 'Outer form', 
    width: 500, 
    height: 500, 
    bodyPadding: 10, 
    renderTo: Ext.getBody() 
});