【发布时间】:2012-05-26 21:44:33
【问题描述】:
我试图让最基本的东西在 Backbone.js 中运行,但不知何故失败了。我为将 url 模型保存到服务器而生成的代码。
urlToAdd.set({url: urlBody.value, tags:tagsToAdd});
urlToAdd.save({
success:function(){
console.log('it works');
}
});
它 成功 将数据发送到我的 php 页面,但是我无法让 success 事件正常工作。我在哪里做错了?我仔细观察了,没发现什么。
这是我的模型定义:(不幸的是,因为我是骨干菜鸟,我已经通过查看教程应用了这个,但我不知道 url 函数中的代码是否必要
var URLWithTags=Backbone.Model.extend({
initialize:function(){
console.log('URL object has been initialized');
},
defaults:{
url:'not defined',
tags:[]
},
validate:function(attributes){
//console.log(attributes.tags[0].length);
/*if(attributes.tags[0].length<1)
return "You should create at least one tag";*/
},
urlRoot:'/URLTags/manage.php',
url:function(){
var base = this.urlRoot || (this.collection && this.collection.url) || "/";
console.log("Base has been produced");
if(this.isNew())
return base;
return base+"?id="+encodeURIComponent(this.id);
},
});
【问题讨论】:
-
@Gohn67 感谢您的评论。我的不同,因为我调用了模型的保存函数
标签: php javascript backbone.js