0

I have one ItemView, then I send throw .trigger() to another controller

Message View

Bintime.module("Message.Input", function(Input, Bintime, Backbone, Marionette, $, _) {
    Input.Contacts = Marionette.ItemView.extend ({
        template: "#new",
        events: {
            "change input#message-input": "sendInput"
        },
        sendInput: function(e){
            e.preventDefault();
            var message = this.$("input#message-input").val();
            this.model.get("messages").push({
                to: "1",
                message: message
            });
            this.render();
            this.trigger("chat:contacts", this.model);
        }
    });
});

Message Controller

Bintime.module("Message.Input", function(Input, Bintime, Backbone, Marionette, $, _) {
    Input.Controller = {
        messageField: function(model){
            var contacts = new Input.Contacts({
                model: model
            });

            contacts.on("childview:chat:contacts", function(childView, model) {
                Bintime.Contacts.Messages.Controller.chatMessages(model);
            });

            Bintime.regions.input.show(contacts);
        }
    }
});

And here is chat controller

Bintime.module("Contacts.Messages", function(Messages, Bintime, Backbone, Marionette, $, _) {
    Messages.Controller = {
        chatMessages: function(model){
            var contacts = new Messages.Contact({
                model: model
            });

            Marionette.Renderer.render("#message", model);

            Bintime.regions.messages.show(contacts);
        }
    }
});

Is it everything true, and should working with Marionette.Renderer.render("#message", model);

Or I should use another method to work with this?

AleshaOleg
  • 2,171
  • 1
  • 15
  • 29

1 Answers1

0

I'm not 100% certain what you're doing with the renderer, but one issue is that your ItemView is not going to prefix its events with "childview:" so that binding should look more like contacts.on("chat:contacts"

Also instead of Bintime.Contacts.Messages.Controller.chatMessages(model); you might throw a Wreqr/Radio event that the other module can listen to.. but I think the biggest issue here is that "childview:chat:contacts" isn't an event that is getting thrown.

Paul Falgout
  • 121
  • 4