Skip to content

Instantly share code, notes, and snippets.

@aaronksaunders
Created February 27, 2013 02:59
Show Gist options
  • Save aaronksaunders/5044613 to your computer and use it in GitHub Desktop.
Save aaronksaunders/5044613 to your computer and use it in GitHub Desktop.
hack to simplify models in Alloy
// create model factory, pass in Alloy global object
var MODELS = new (require('models').MODELS)(Alloy);
var person = new MODELS.Person({
"name" : "Reina Saunders",
"age" : 2
});
person.save(null, {
"success" : function(_m, _r) {
Ti.API.info('person ' + JSON.stringify(_m.attributes));
},
"error" : function(_m, _r) {
Ti.API.error('person ' + JSON.stringify(_m));
}
});
exports.MODELS = MODELS = function(_Alloy) { debugger;
// this accounts for requires implementation and global
// Alloy object and the underscore library
var A = ( typeof Alloy === "undefined" ? _Alloy : Alloy );
var _ = A._;
A.Backbone.sync = require('ti_rest').sync
//
// MODELS
//
//
var Person = A.Backbone.Model.extend({
url : function() {
return A.CFG.PEOPLE_URL + "/" + this.id
}
});
var People = A.Backbone.Collection.extend({
model : Person,
url : A.CFG.PEOPLE_URL + "/?"
});
return {
"Person" : Person,
"People" : People,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment