backbone.js - override get method in Alloy model -
i'm trying override get: calls in alloy model, similar backbone, wrote doesn't work
extendmodel: function(model) { _.extend(model.prototype, { // extended functions , properties go here get: function (attr) { if (attr=='image') { return ti.utils.base64decode(this['image']) } return this[attr]; } }); return model; },
here how overriding set , add methods hope helps you:
exports.definition = { config: { adapter: { type: "properties", collection_name: "carecenter", idattribute : "carecenterid" } }, extendmodel: function(model) { _.extend(model.prototype, { idattribute : "carecenterid" // extended functions , properties go here }); return model; }, extendcollection: function(collection) { _.extend(collection.prototype, { add : function(attrs, opts){ var isduplicated = false; if(attrs && attrs.get){ isduplicated = this.any(function(model){ return model.get("carecenterid") === attrs.get("carecenterid"); }); } if(isduplicated){ return false; } else { backbone.collection.prototype.add.call(this, attrs, opts); } }, comparator : function(model){ return -model.get("state"); } }); return collection; } } extendmodel: function(model) { _.extend(model.prototype, { idattribute : "recipientid", set : function(attrs, opts){ if(attrs.age != null){ var age = attrs.age; var result = ""; if(age <= alloy.cfg.infant){ result = "infant"; } else if(age <= alloy.cfg.child){ result = "child"; } else if(age <= alloy.cfg.teenager){ result = "teenager"; } else { result = "adult"; } attrs.group = result; } return backbone.model.prototype.set.call(this, attrs, opts); } }); return model; },
Comments
Post a Comment