1

我列出了一个带有一个复选框和描述的集合。现在,当用户单击提交按钮时,我想验证用户是否应该至少单击一个复选框。我知道集合中有一个事件“更改”,但不知道如何使用它。

我希望这个集合应该有一个布尔类型的属性来检查集合是否被改变。

4

1 回答 1

0

谢谢你的及时回复。我知道我可以使用集合的更改事件。我想知道我的解决方案是否正确。这是我的代码。请注意,在呈现我的视图后注册事件,因为默认情况下我更改了一些值。

complienceListView = Backbone.View.extend({
    el: $('#complienceList'),
    initialize: function () {
      complienceList.bind("reset", this.render, this);     
    },
    render: function () {
        complienceList.each(function (complience) {
        $(this.el).append(new complienceListItemView({ model: complience }).render().el);
        }, this);
        complienceList.on('change', function(){isDirty = true;})
        return this;
    }
});

var isDirty = false;
于 2013-04-07T10:24:16.873 回答