exports.definition = {
config : {
// table schema and adapter information
},
extendModel: function(Model) {
_.extend(Model.prototype, {
// Extend, override or implement the Backbone.Model methods
});
return Model;
},
extendCollection: function(Collection) {
_.extend(Collection.prototype, {
// Implement the comparator method.
comparator : function(book) {
return book.get('title');
}
}); // end extend
return Collection;
}
}
我应该在哪里指定url属性以与我的其他服务进行通信。
http://docs.appcelerator.com/titanium/latest/#!/guide/Alloy_Models
答案 0 :(得分:2)
exports.definition = {
config: {
"columns": {
"username": "",
"password": ""
},
"defaults": {
"username": "-",
"password": "-"
},
"adapter": {
"type": "restapi",
"collection_name": "user"
}
},
extendModel: function(Model) {
_.extend(Model.prototype, {
**urlRoot**:'',
checkLogin: function(){
}
});
return Model;
},
extendCollection: function(Collection) {
_.extend(Collection.prototype, {
// Extend, override or implement Backbone.Collection
});
return Collection;
}
}
Backbone.sync方法在创建这些类时,对Model.urlRoot或Collection.url属性指定的URL执行RESTful JSON请求。您可以在Model or Collection
中指定。
答案 1 :(得分:0)
我真的不知道appcelerator,但是在骨干中你在Collection中添加了url配置,请检查here
答案 2 :(得分:0)
我不确定如何在Appcelerator中执行此操作,但仅Backbone解决方案是您需要将url选项传递给您的模型或集合。
首先,您需要创建Backbone模型定义url(urlRoot for collection),然后在Appcelerator模型中扩展它们。
以下是钛文件的解释。
“由于Backbone主要用于Web应用程序,因此默认情况下, Backbone.sync方法对指定的URL执行RESTful JSON请求 通过Model.urlRoot或Collection.url属性,当这些类时 被创造了。 “