Javascript 主干形式。js文档示例:Onchange Populator:如何隐藏第二个select并在更改事件后显示它?

Javascript 主干形式。js文档示例:Onchange Populator:如何隐藏第二个select并在更改事件后显示它?,javascript,backbone.js,backbone-forms,Javascript,Backbone.js,Backbone Forms,这是我想学习的文档中的代码。 在我看来,在触发更改事件时,隐藏第二个select并显示它会很酷。我尝试了一些功能注射,但效果不好。有人能给这个问题2美分吗 (function($) { var cities = { 'UK': ['London', 'Manchester', 'Brighton', 'Bristol'], 'USA': ['Washington DC', 'Los Angeles', 'Austin', 'New York'] }

这是我想学习的文档中的代码。 在我看来,在触发更改事件时,隐藏第二个select并显示它会很酷。我尝试了一些功能注射,但效果不好。有人能给这个问题2美分吗

(function($) {
    var cities = {
        'UK': ['London', 'Manchester', 'Brighton', 'Bristol'],
        'USA': ['Washington DC', 'Los Angeles', 'Austin', 'New York']
    };

    //The form
    var form1 = new Backbone.Form({
        schema: {
            country: { type: 'Select', options: ['UK', 'USA'] },
            city: { type: 'Select', options: cities.UK },
            message: { type: 'Text'}
        }
    }).render();

    form1.on('country:change', function(form1, countryEditor) {
        var country = countryEditor.getValue(),
            newOptions = cities[country];
            form1.fields.city.editor.setOptions(newOptions);

    });

    //Add it to the page
    $('body').append(form1.el);
})(jQuery);

form1.fields['message'].$el.hide()

在渲染和


form1.fields['message'].$el.toggle() 在内部,on change函数解决了这个问题

(function($) {
    var cities = {
        'UK': ['London', 'Manchester', 'Brighton', 'Bristol'],
        'USA': ['Washington DC', 'Los Angeles', 'Austin', 'New York']
    };

    //The form
    var form1 = new Backbone.Form({
        schema: {
            country: { type: 'Select', options: ['UK', 'USA'] },
            city: { type: 'Select', options: cities.UK },
            message: {  
                //fieldAttrs: { style: 'width: 400px; height:300px;' }, 
                type: 'TextArea',
                fieldClass: 'message-input', 
                validators: [ 'required', /.{20,}/ ] 
            }
        }
    }).render();
    **form1.fields['message'].$el.hide();**

    *form1.on('country:change',* function(form1, countryEditor) {
        var country = countryEditor.getValue(),
            newOptions = cities[country];
            form1.fields.city.editor.setOptions(newOptions);
            **form1.fields['message'].$el.toggle();**
    });

    //Add it to the page
    $('body').append(form1.el);
})(jQuery);