How to use logical operators inside bind formulas in ExtJS?

拥有回忆 提交于 2019-12-05 05:49:32

In the view model, add a formula to return the value for {!field1.value} || {!field1.value}

As per the fiddle:

viewModel: {
    formulas: {
        something: {
            bind: {
                x: '{!field1.value}',
                y: '{!field2.value}'
            },

            get: function (data) {
                if (data.x || data.y) return true;
                else return false;
            }
        }
    }
},

items: [{
    xtype: 'form',
    defaultType: 'textfield',
    bodyPadding: 10,
    items: [
        {fieldLabel: 'Field 1', reference: 'field1', publishes: 'value'},
        {fieldLabel: 'Field 2', reference: 'field2', publishes: 'value'},
        {
            fieldLabel: 'Field 3', 
            bind: {
                disabled: "{something}"
            }
        },            
    ],

}]

Add a formulas configuration to your ViewModel like this:

formulas : {
        showSomeComponent : function (get) {
            return get('isAuthorized') && !get('isDisabled');
        }
    }

http://docs.sencha.com/extjs/5.1.0/Ext.app.ViewModel.html#cfg-formulas

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!