Backbone.js 如何在主干中保存输入字段中的数据?
我有个问题-我需要将表单中的数据放入数据库…使用主干网! 怎么做? 我需要在我的纸条和HTML中写什么? 我的收藏是:Backbone.js 如何在主干中保存输入字段中的数据?,backbone.js,Backbone.js,我有个问题-我需要将表单中的数据放入数据库…使用主干网! 怎么做? 我需要在我的纸条和HTML中写什么? 我的收藏是: define([ "underscore", "backbone", "jquery" ], function(_, Backbone, $) { return Backbone.Collection.extend({ url: '/users/all' //route
define([
"underscore",
"backbone",
"jquery"
],
function(_, Backbone, $) {
return Backbone.Collection.extend({
url: '/users/all' //route for get ALL users in DB
});
});
您只需创建一个方法,每当用户点击submit时,该方法就会在html表单上进行迭代:
store: function(e)
{
e.preventDefault();
//select each input, select and textarea within this views $el
_.each(this.$('input, select, textarea'), function(input)
{
//you input name attribute to set the correct model attribute.
this.model.set(input.name, input.value);
}, this);
//new model attributes from the form are now available and ready to be synced
//with the server.
console.log(this.model.toJSON());
}
看看这个