Node.js 如何将Parse.com与Node/Express和主干一起使用
我的待办事项清单已经准备好了。如果我按“添加”按钮添加一个新的todo,我可以坚持使用主干解析.com。唯一的问题是,如果我刷新页面,我刚才添加的所有待办事项都会消失。这是正确的,因为我现在实际上没有使用后端 在与Node/express集成时,我如何向parse.com发出post请求并获取当前的TODO 我在一篇教程中读到这样的内容:Node.js 如何将Parse.com与Node/Express和主干一起使用,node.js,backbone.js,express,parse-platform,Node.js,Backbone.js,Express,Parse Platform,我的待办事项清单已经准备好了。如果我按“添加”按钮添加一个新的todo,我可以坚持使用主干解析.com。唯一的问题是,如果我刷新页面,我刚才添加的所有待办事项都会消失。这是正确的,因为我现在实际上没有使用后端 在与Node/express集成时,我如何向parse.com发出post请求并获取当前的TODO 我在一篇教程中读到这样的内容: var Todos = Backbone.Collection.extend({ url: 'http://localhost:3000/api/todo
var Todos = Backbone.Collection.extend({
url: 'http://localhost:3000/api/todos'
});
var TodosView = Backbone.View.extend({
model: todos,
el: $('.todos-list'),
initialize: function() {
this.model.on('add', this.render, this);
this.model.on('remove', this.render, this);
//this thing-----------
this.model.fetch({
success: function(response){
_.each(response.toJSON(), function(item) {
console.log('Successfully GOT todo with _id: '+ item._id);
});
},
error: function() {
console.log('Failed to get blogs!');
}
})
},
//this thing end-----------
render: function() {
var self = this;
this.$el.html('');
_.each(this.model.toArray(), function(todo) {
self.$el.append((new TodoView({model: todo})).render().$el);
});
return this;
}
});
像这样的:
var Todos = Backbone.Collection.extend({
url: 'http://localhost:3000/api/todos'
});
var TodosView = Backbone.View.extend({
model: todos,
el: $('.todos-list'),
initialize: function() {
this.model.on('add', this.render, this);
this.model.on('remove', this.render, this);
//this thing-----------
this.model.fetch({
success: function(response){
_.each(response.toJSON(), function(item) {
console.log('Successfully GOT todo with _id: '+ item._id);
});
},
error: function() {
console.log('Failed to get blogs!');
}
})
},
//this thing end-----------
render: function() {
var self = this;
this.$el.html('');
_.each(this.model.toArray(), function(todo) {
self.$el.append((new TodoView({model: todo})).render().$el);
});
return this;
}
});
this.model.fetch正在尝试从上面的url获取,但该教程使用的是MongoDB。我如何使用parse.com做同样的事情
如果你能解释你的答案,那就太棒了,因为我昨天刚刚试着学习主干/节点/表达式/解析
var Messages = Backbone.Collection.extend({
model:Message,
url:'https://api.parse.com/1/something/something',
getMessages:function() {
this.fetch({
data:{
order:'-createdAt'
}
});
},
parse:function(response, options) {
return response.results.reverse();
}
});
在您的示例中,您正在获取并发布到自己的计算机http://localhost:3000/api/todos
我猜您从教程中学到了这一点。在parse.com上设置和帐户,并签出码头。您将更改url以匹配其API。查看他们的RESTAPI文档了解详细信息
在您的示例中,您正在获取并发布到自己的计算机http://localhost:3000/api/todos
我猜您从教程中学到了这一点。在parse.com上设置和帐户,并签出码头。您将更改url以匹配其API。查看他们的RESTAPI文档了解详细信息