Open EtnaTraining opened 9 years ago
If you're trying to define the model in the controller, why can't you also set the label's text in the controller?
$.year.text = currentMovie.get('year') || '';
Sure, I can do that, but this is actually a demo app to showcase Alloy & Titanium and the point is to demonstrate how can we do data binding between view and models, as React Native will do. Using data binding is a cleaner option than updating view attributes from controller IMHO.
Currently the info of the selected movie are retrieved from a global (singleton) model defined in
alloy.js
:A more clean approach would use a local instance of the model in the detail.js controller. But currently it's not possible to bind a local model created directly via Backbone APIs, as far as I know, because the local model instance should exists BEFORE the XML view il loaded (and bound). This works fine if using Alloy model with a Movie.js file defined and using a Model tag into the XML:
If I try to manually create a model instance in the detail.js controller with:
the binding in the XML view will fail:
trying to look for a global
Alloy.Models.currentMovie
anyway.I suspect there is no way to bind a local Backbone model to a View attribute