2017-09-01 106 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() 
});