EtnaTraining / MoviesDemo

This demo show how we can build with Appcelerator Titanium the same app demonstrated during the Facebook React Native demo
55 stars 17 forks source link

Cannot mix text and model attributes when binding with the movieList collection #3

Open EtnaTraining opened 9 years ago

EtnaTraining commented 9 years ago

Currently the info of the selected movie are retrieved from a global (singleton) model defined in alloy.js:

Alloy.Models.currentMovie = new Backbone.Model();

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:

<Model id="currentMovie" src="Movie" instance="true"/>

If I try to manually create a model instance in the detail.js controller with:

$.currentMovie = new Backbone.Model()

the binding in the XML view will fail:

<Label id="year" text="{currentMovie.year}"></Label>

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

skypanther commented 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') || '';
EtnaTraining commented 9 years ago

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.