Last active
December 11, 2015 11:08
-
-
Save bhatfield/4591180 to your computer and use it in GitHub Desktop.
Alloy Plain Backbone Model-View Binding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
".container": { | |
backgroundColor:"white" | |
}, | |
"Label": { | |
width: Ti.UI.SIZE, | |
height: Ti.UI.SIZE, | |
color: "#000" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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