javascript - Alloy Collection and Models for POST data -
i'm not new titanium means, quite new alloy , trying grasp concept of collections , models.
my first view/controller login screen naturally need submit username , password api. found , able retrieve illustration json feed: https://github.com/viezel/napp.alloy.adapter.restapi
in models folder, have model called login
(or it, have collection?)
exports.definition = { config: { "url": "http://example.com/services/user/login", "debug": 0, "adapter": { "type": "restapi", "collection_name": "login", "idattribute": "id" }, "headers": {}, "parentnode": "feed" //your root node }, extendmodel: function(model) { _.extend(model.prototype, {}); homecoming model; }, extendcollection: function(collection) { _.extend(collection.prototype, {}); homecoming collection; } };
my controller calls model via:
var login = alloy.createcollection('login'); login.fetch({ success : function() { _.each(login.models, function(element, index, list) { //-- handle response }); }, error : function() { ti.api.error('xhr error!'); } });
my question, isn't clear on aforementioned link, how post info model send api. said, need send username , password.
i have pretty thorough examples of this.
but basic premise need extend user model back upwards login function, not in collection.
see finish illustration here https://github.com/aaronksaunders/appc-alloy-book/blob/master/app/models/user.js
although model acs, basic pattern remains same
extendmodel : function(model) { _.extend(model.prototype, { login : function(_login, _password, _callback) {} } }
javascript titanium appcelerator titanium-alloy
No comments:
Post a Comment