Marionette 2.2如何听到触发事件?

时间:2014-11-13 15:18:41

标签: jquery backbone.js marionette

它与之前版本的marionette配合得很好。现在我更新到2.2更新版本。但我现在无法听到我的触发器。

我知道它已更新并改变了方法。任何人都指导我采用新方法吗?

我在itemView中的触发器:

List.Contact = Marionette.ItemView.extend({
        tagName : "tr",
        events: {
            "click": "highlightName"
        },

        triggers : {
            "click button.js-delete" : "contact:delete" // i trigger delete from here
        },
        template : "#contact-list-item",
        highlightName: function (e){
            e.preventDefault();
            this.$el.toggleClass("warning");
        },
        remove : function () {
            var self = this;
            this.$el.fadeOut('slow', function() {
                Marionette.ItemView.prototype.remove.call(self);
            });
        }
    });

这是我试图听到我的触发器:(控制器)

List.Controller = {
        listContacts : function () {
            var contacts = ContactManager.request("contact:entities");

            var contactsListView = new List.Contacts({
                collection : contacts
            });

            contactsListView.on("itemview:contact:delete", function (childView, Model) {
                console.log("i am hearing!"); //not working at all...
                contacts.remove(model); //is the way is wrong?
            });

            ContactManager.mainRegion.show(contactsListView);
        }
    }

两者都嵌套了单独的模块。请帮我。 提前谢谢!

1 个答案:

答案 0 :(得分:0)

我更新了itemview - 进入childview - 它的工作正常。

List.Controller = {
        listContacts : function () {
            var contacts = ContactManager.request("contact:entities");

            var contactsListView = new List.Contacts({
                collection : contacts
            });

            contactsListView.on("childview:contact:delete", function (childView, Model) {
                console.log("i am hearing!"); //not working at all...
                contacts.remove(model); //is the way is wrong?
            });

            ContactManager.mainRegion.show(contactsListView);
        }
    }