如果有一个小游戏,必须将图像拖到较大图像的右侧热点上。
小图像在 containerView 内,热点也是 ContainerViews。当我将图像放在热点上时,我在拖放混合中使用以下代码在 dom 中移动图像:
Player.Droppable = Ember.Mixin.create({
drop: function(event) {
//get the view that was dragged
var viewId = event.originalEvent.dataTransfer.getData('Text');
var view = Ember.View.views[viewId];
//log the parent-view: App.AnswerListView
console.log(view.get('parentView').constructor);
//detach the view from the original containerView
var parentView = view.get('parentView');
parentView.removeObject(view);
//attach it to the hot-spot-containerview
this.addObject(view);
//logging this gives a different result: App.HotspotView
console.log(view.get('parentView').constructor);
event.preventDefault();
return false;
}
});
我拖动的视图是 App.AnswerView。我对文档的期望是 AnswerView 上的函数 parentViewDidChange 被触发,但这不会发生:
App.AnswerView = Ember.View.extend(App.Draggable, {
templateName: "answer",
classNameBindings: [':answer', 'this.content.isSelected:selected'],
click: function(evt){
this.get('controller').send('answerClicked', this.content);
},
parentViewDidChange: function(){
this.get('controller').send('answerMoved', this.content);
},
});
文档说:当 parentView 属性更改时调用。就我而言,它已更改。这是一个错误,还是我在这里遗漏了什么?
TIA