Skip to content

Instantly share code, notes, and snippets.

@bhatfield
Last active December 11, 2015 11:08
Show Gist options
  • Save bhatfield/4591180 to your computer and use it in GitHub Desktop.
Save bhatfield/4591180 to your computer and use it in GitHub Desktop.
Alloy Plain Backbone Model-View Binding
var collection = Backbone.Collection.extend({
comparator: function(model){
return model.get('title');
}
});
var library = new collection([
{title: 'To Kill a Mockingbird', author:'Harper Lee'},
{title: 'The Catcher in the Rye', author:'J. D. Salinger'},
{title: 'Of Mice and Men', author:'John Steinbeck'},
{title: 'Lord of the Flies', author:'William Golding'},
{title: 'The Great Gatsby', author:'F. Scott Fitzgerald'},
{title: 'Animal Farm', author:'George Orwell'}
]);
Alloy.Collections.book = library;
Ti.API.info(JSON.stringify(library));
$.index.open();
Ti.API.info(JSON.stringify(Alloy.Collections.book));
var library = Alloy.Collections.book;
var model = Backbone.Model.extend();
var book = new model({title:'Bossypants', author:'Tina Fey'});
library.add(book);
model = library.at(0);
var title = model.get('title');
Ti.API.info(title);
library.remove(model);
".container": {
backgroundColor:"white"
},
"Label": {
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
color: "#000"
}
<Alloy>
<Window class="container">
<TableView id="label" dataCollection="book">
<TableViewRow title="{title}" />
</TableView>
</Window>
</Alloy>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment