从视图调用 ViewController 中的验证器方法

Call validator method in ViewController from the View

我正在学习 Ext JS 5.1。
是否可以从视图中调用 ViewController 中定义的验证器方法?

我的视图

    {
        xtype: 'textfield',
        margin: '0 0 10 0',
        fieldLabel: 'Password',
        name: 'pass1',
        reference: 'pass1',
        inputType: 'password',
        allowBlank: false,
        minLength: 5
    },
    {
        xtype: 'textfield',
        margin: '0 0 10 0',
        fieldLabel: 'Confirm Password',
        name: 'pass2',
        reference: 'pass2',
        inputType: 'password',
        allowBlank: false,
        validator: 'checkPassword' // want to call method that defined in ViewController
    }

我的ViewController

    checkPassword: function(value){
        var pass1val = this.lookupReference('pass1').getValue();
        if (value == pass1val){
            return true;
        }
        else{
            return "The initial password and the re-typed password do not match.";
        }
    }

目前,您不能。但你应该能够。我会记录一个票来解决这个问题。

我目前针对 v5.1 的解决方法如下(示例 here):

      // ...in ViewController
        init: function() {
            var startCombo = this.lookupReference('startCombo');
            var endCombo = this.lookupReference('endCombo');
            startCombo.validator = Ext.bind(this.comboValidator, this, [startCombo, endCombo]);
            endCombo.validator = Ext.bind(this.comboValidator, this, [startCombo, endCombo]);
        },
        comboValidator: function(startCombo, endCombo) {
            return startCombo.getValue() < endCombo.getValue();
        },