Skip to content

Instantly share code, notes, and snippets.

@skypanther
Created May 6, 2014 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skypanther/93549e31070f1093b8ce to your computer and use it in GitHub Desktop.
Save skypanther/93549e31070f1093b8ce to your computer and use it in GitHub Desktop.
Sample Alloy project with view/model binding
Alloy.Globals.winTop = (OS_IOS && parseInt(Ti.Platform.version, 10) >= 7) ? 20 : 0;
Ti.UI.backgroundColor = "#fff";
Ti.API.info('seeded: ' + Ti.App.Properties.hasProperty('seeded'));
if (!Ti.App.Properties.hasProperty('seeded')) {
for(var i=1,j=7;i<j;i++) {
Alloy.createModel('rows', { title: 'Row '+i}).save();
}
Ti.App.Properties.setString('seeded', 'yes');
}
Alloy.Collections.rows.fetch();
$.addRow.addEventListener('click', function(){
Alloy.createModel('rows', { title: 'Row ' + (Alloy.Collections.rows.size()+1)}).save();
Alloy.Collections.rows.fetch();
});
$.index.open();
".container": {
backgroundColor:"white",
top: Alloy.Globals.winTop
},
"Label": {
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
color: "#000"
}
"#addRow": {
top: 0,
title: 'Add a row',
height: '30dp'
}
"TableView": {
top: '40dp'
}
<Alloy>
<Collection src="rows" />
<Window id="index" title="Model Test" class='container'>
<Button id="addRow"/>
<TableView id="table" dataCollection="rows">
<TableViewRow>
<Label text="{title}" left="5"/>
</TableViewRow>
</TableView>
</Window>
</Alloy>
exports.definition = {
config: {
"columns" : {
"title" : "text"
},
adapter: {
type: "sql",
collection_name: "rows"
}
},
extendModel: function(Model) {
_.extend(Model.prototype, {
// extended functions and properties go here
});
return Model;
},
extendCollection: function(Collection) {
_.extend(Collection.prototype, {
// extended functions and properties go here
});
return Collection;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment