Gettting Models/Collections to update Views

I think I'm missing something basic with new MVC enyo. I can successfully create Models/Collections and instantiate them from views. I can cause the collection to load (fetchAndReplace) and I see the updated data from the view.

However, I can't figure out how to get the Model/Collection to report to View that it has been changed. What I've been doing is one of three things, either 1) send in a success function from View into the fetchAndReplace; 2) create an event in the Model/Collection like "onDataChange" and send in the function from the View; 3) creating a binding in View from .collectionName.status to .collectionStatus and then using a function called collectionStatusChanged in the View.

All the above seem a bit "hacky" - is there an easier way that I'm missing?



  • How are you modifying the models? We setup observers between the fields in the models and the view as part of our bindings, but for those to fire, you need to use the .set method to modify model fields.
  • I'm just doing a this.CollectionName.fetchAndReplace(options). Are you saying I should bind each of the parameters from Model or Collection to the view in a bindings:[{from:".CollectionName.variableName", to:".ViewVariableName"}]? I can see how it may work for model but would this work for Collection which is an array of models?
  • @psarin I am typically using collections when I want to deal with a DataList/DataRepeater. The "view" (list item component) has the model set on it when the collection updates. So your view would set up a bindings block as per normal, then each instance of it will have its model set by the DataRepeater/DataList.

    Another option is to listen for onModelAdded or onModelsAdded (or Changed, Deleted, etc.) and then construct/destroy the components by hand. This technique is useful if you want to drive a bunch of views in enyo.Panels or something. For instance, you have an enyo.Panels with a controller that is actually a Collection, so you listen for models being added to it to construct your Panels views.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!