0
votes

I have written code using jquery, marionette etc to create my html pages. I want to isolate my views from my business logic, which i believe is d proper way :).

I have created a generalized Marionette.Layout for the html page by passing Marionette.ItemView's through parameters in a function. Here's a link to my code!

Normally if we want to handle a button click within an ItemView we would use events:{click .btnSubmit = buttonClicked}, but what i want is the that the events associated with a page should be handled from different script file so that whenever i change my view my business logic won't get affected. If you will go through my code i have created a script file busn_logic.js from where i want to handle all my click events on any ItemView.

So please help me. Thanks in advance.

1

1 Answers

0
votes

For this, you want to use application events. From your view, call MyApp.trigger("submit:button:clicked"), then in your business logic file, listen for that event:

MyApp.on("submit:button:clicked", function(){
  // process the event here
})

(Note that you can also pass arguments on the event trigger, e.g. the clickevent.)

And if you need your business logic to control the views, use triggerMethod like this: https://github.com/davidsulc/marionette-gentle-introduction/blob/master/assets/js/apps/contacts/list/list_controller.js#L61