Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Templated Event Binding on Models Without Live Binding

$
0
0
If I fetch a list of models in the init() of a can.Control and want to listen to changes in any of the models. How do I do this if none of the models have live binding setup? 

The problem occurs when I issue any additional findAll calls. At that point the templated event binding stops working. Ideally, what I want is that on subsequent findAll calls, if any of the models have changed, my change function will be executed.

But it seems that if the model is not in the store (no live binding) that on subsequent findAll calls, the change event is not fired.

  1. init: function() {
          var self = this;
          can.when(myModel.findAll()).then(function(models) {
                self.options.models = models;
                self.on();
          });
    },

    "{models} change": function(StatusList, ev, attr, changeType, newVal, oldVal) {
          // Do something
    },

    update: function() {
          can.when(myModel.findAll()).then(function(models) {

                // Templated event binding no longer works because it is a new object
                self.options.models = models;
          });
    }


Is there a way to do this?

Viewing all articles
Browse latest Browse all 3491

Trending Articles