让我的视图更新放置事件时遇到了一些麻烦。我很确定问题出在函数 handleDrop() 中。视图的重新渲染在浏览器中的普通 model.set({}) 测试中起作用。所以,我知道这不是问题所在......
骨干路由器
App.Routers.Dashboard = Backbone.Router.extend({
routes: {
"": "index"
},
initialize: function(options) {
},
index: function() {
var preflist = new App.Models.PrefList({});
preflist.fetch({
success: function() {
var paneloneview = new App.Views.PanelOne({ model: preflist });
$('#panelone').html(paneloneview.render().$el);
}
});
var sourceID;
var payloads = {
poolpricedraggable: "poolprice",
nonedraggable: "smp"
};
var element = function(id) { return document.getElementById(id); }
function handleDragOver(event) {
if(event.preventDefault) event.preventDefault();
return false;
}
function handleDrop(event) {
dropzone = this.id;
if(event.preventDefault) event.preventDefault();
console.log("recevied the data: " + payloads[sourceID] + " in #" + dropzone);
var attribute = preflist.get('panel_one');
preflist.set({panel_one: attribute});
preflist.save();
}
element('panelone').addEventListener('dragover', handleDragOver, false);
element('panelone').addEventListener('drop', handleDrop, false);
PanelOne 视图
App.Views.PanelOne = Backbone.View.extend({
initialize: function() {
_.bindAll(this, 'render');
this.model.bind('change', this.render);
},
render: function(){
var panelonesetting = this.model.get('panel_one');
this.$el.html(JST['dashboard/' + panelonesetting]({}));
return this;
}
});
最诚挚的问候,交流