Created
May 6, 2014 15:31
-
-
Save skypanther/93549e31070f1093b8ce to your computer and use it in GitHub Desktop.
Sample Alloy project with view/model 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
Alloy.Globals.winTop = (OS_IOS && parseInt(Ti.Platform.version, 10) >= 7) ? 20 : 0; | |
Ti.UI.backgroundColor = "#fff"; |
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
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(); |
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", | |
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' | |
} |
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> | |
<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> |
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
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