I have a Titanium/Appcelerator app created using Alloy models, which uses Backbone.js. Each model has a text field that I would like to interpret as a number. So far I've been getting the property and converting it using parseInt()
each time I need to use it.
Is there a way to automatically interpret that property as a number every time I access it? Perhaps some kind of automatic conversion? I would like to avoid changing the type of the field in the database and having to do some kind of migration.
Here is a stripped down example of my model. The property date
is saved to the database as a string. But because it's a UTC timestamp, I want to always interpret it as a number.
exports.definition = {
config: {
columns: {
"name": "text",
"date": "text"
},
adapter: {
type: "sql",
collection_name: "people"
}
},
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
});
return Collection;
}
};