我无法让表单对象发布,这是我到目前为止使用测试数据得到的结果,我得到的 setTarget.save 是未定义的。我能够使用类似的结构成功获取 fetch/get 调用。
风景
define([
'jquery',
'underscore',
'backbone',
'text!templates/default/parent.html'
], function($, _, Backbone, parentTemplate) {
var defaultView = Backbone.View.extend({
initialize: function() {
$(this.el).html(parentTemplate);
this.render();
},
events: {
'click #busNext': 'showTarget'
},
showTarget: function() {
this.model.set({
businessName: $('#busInfoName').val(),
});
this.model.save();
},
render: function() {
this.setValidator();
return this;
}
});
return new defaultView;
});
该模型
define([
'underscore',
'backbone'
], function(_, Backbone) {
var setTarget = Backbone.Model.extend({
initialize: function() {
console.log('set target initialize');
},
url: 'test.htm',
defaults: {
businessName: "",
businessPhone: ""
}
});
return setTarget;
});
收藏品
define([
'jquery',
'underscore',
'backbone',
'models/setTarget'
], function($, _, Backbone, setTarget){
var target = Backbone.Collection.extend({
model: setTarget,
});
return new target;
});
路由器
define([
'jquery',
'underscore',
'backbone',
'validate',
'views/default/parent',
'models/setTarget',
'collections/target'
], function($, _, Backbone, validate, defaultView, setTarget, target) {
var AppRouter = Backbone.Router.extend({
routes: {
'': 'defaultAction',
'index': 'defaultAction',
},
defaultAction: function(actions) {
this.changePage(defaultView, 'fade');
},
changePage: function(page, pageTransition) {
$('body').append($(page.el));
$.mobile.changePage($(page.el), { changeHash: true, transition: pageTransition });
}
});
var initialize = function() {
var app_router = new AppRouter;
Backbone.history.start();
};
return {
initialize: initialize
};
});