Last active
June 3, 2016 17:25
-
-
Save grantges/859c9e6a53264e7fc0e7 to your computer and use it in GitHub Desktop.
Model Extension in Appcelerator 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
var modelOne = Alloy.createModel('modelOne'); | |
var modelTwo = Alloy.createModel('modelTwo',{ | |
name: "Bert", | |
description: "is the man", | |
URL:"thisisawesome.com" | |
}); | |
Ti.API.info(modelTwo.config); | |
modelTwo.save(); | |
$.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
exports.definition = { | |
config: { | |
columns: { | |
"name": "string", | |
"description": "string" | |
}, | |
adapter: { | |
type: "sql", | |
collection_name: "modelOne" | |
} | |
}, | |
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 | |
// For Backbone v1.1.2, uncomment the following to override the | |
// fetch method to account for a breaking change in Backbone. | |
/* | |
fetch: function(options) { | |
options = options ? _.clone(options) : {}; | |
options.reset = true; | |
return Backbone.Collection.prototype.fetch.call(this, options); | |
} | |
*/ | |
}); | |
return Collection; | |
} | |
}; |
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 Alloy = require('alloy'); | |
var baseModel = Alloy.createModel('test'); | |
Ti.API.info( baseModel.config); | |
exports.definition = { | |
config: { | |
columns: _.extend(baseModel.config.columns, { | |
"URL": "string" | |
}), | |
adapter: { | |
type: "sql", | |
collection_name: "test2" | |
} | |
}, | |
extendModel: function() { | |
Ti.API.info('EXTEND MODEL'); | |
var model = _.clone(baseModel.prototype); | |
_.extend(model, { | |
// your props/methods here | |
}); | |
return model | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment