Javascript 在主干网中将数据从一个模型传递到另一个模型
问题:我想创建一个新的模型,该模型获取这个值mynumber并进行POST请求。到目前为止,我有:Javascript 在主干网中将数据从一个模型传递到另一个模型,javascript,jquery,post,backbone.js,Javascript,Jquery,Post,Backbone.js,问题:我想创建一个新的模型,该模型获取这个值mynumber并进行POST请求。到目前为止,我有: $("#button").click(function(){ var mynumber = $("#one").val() + $("#two").val() + $("#three").val(); //IF i do a this.model.save here it will POST all four fields that I dont want }); 我不知道如何将这两者联
$("#button").click(function(){
var mynumber = $("#one").val() + $("#two").val() + $("#three").val();
//IF i do a this.model.save here it will POST all four fields that I dont want
});
我不知道如何将这两者联系起来。我只想发布我的编号,而不是所有的字段。如果有任何帮助,我们将不胜感激
var mymodel = Numbermodel.extend({
this.model.set(mynumber);
this.model.save({},{
success: function(model, response) {
console.log('success! ' + response);
},
error: function(model, response) {
console.log('error! ' + response);
}
});
});
将该代码与html代码一起使用 我的POST请求仍然包含一、二、三、四和我的号码。我可以在设置为mynumber之前销毁模型吗?感谢you@James添加到end
返回false
sentRequest
var mymodel = Numbermodel.extend({
this.model.set(mynumber);
this.model.save({},{
success: function(model, response) {
console.log('success! ' + response);
},
error: function(model, response) {
console.log('error! ' + response);
}
});
});
var FormView = Backbone.View.extend({
tagName: 'form',
events: {
'click #button': 'sentRequest'
},
initialize: function(){
...
},
render : function(){
...
},
sentRequest: function(){
var mynumber = $("#one").val() + $("#two").val() + $("#three").val();
var mymodel = new Numbermodel();
model.set(mynumber);
model.save({},{
success: function(model, response) {
console.log('success! ' + response);
},
error: function(model, response) {
console.log('error! ' + response);
}
});
return false; //return false -- with the code form request does not send
}
})
$(function(){
var view = FormView();
view.render();
});