如何獲得已放置到可放置目標上的jQuery小部件的上下文?jQuery droppable越來越被丟棄的對象上下文
例如這是可拖動與此代碼的插件:
In the code that makes the images be draggable
ContentImageHolder.prototype = {
options: {
contentInfo: null,
},
getContentInfo: function(){
return this.options.contentInfo;
},
makeContentDraggable: function(){
$(this.element).draggable({
revert: true,
scroll: false,
start: $.proxy(this, 'dragStart'),
stop: $.proxy(this, 'dragStop'),
});
},
_init: function() {
this.makeContentDraggable();
}
$.widget("basereality.contentImageHolder", ContentImageHolder);
然後這是我的代碼,使垃圾可以接受的圖像。
TrashCan.prototype = {
trashContent: function (event, ui){
//What do I do here to be able to access the functions of the dropped object
//droppedObject.getContentInfo();
},
_init: function() {
$(this.element).droppable({
drop: $.proxy(this, 'trashContent'),
});
},
}
$.widget.bridge('trashCan', TrashCan);
是否有可能得到的是被拖到可放開,所以我可以在對象上調用函數的ContentImageHolder的背景下?
在這裏所有的問題與類似的關鍵字都說使用ui.draggable
但引用一個DOM對象,而不是jQuery小部件。那麼是否有可能獲得jQuery小部件?
謝謝。如果我知道什麼類型的對象將被拖放到可拖放對象上,那很好用。但是,如果可以刪除多種類型的小部件,您如何獲得對象類型?即如何知道我可以調用$(ui.draggable).contentImageHolder(「getContentInfo」);而不是像$(ui.draggable).contentVideoHolder(「getContentInfo」);如果它是一個被刪除的視頻小部件。 – Danack 2013-02-28 07:11:04
btw感謝您對代碼結構的建議。我實際上使用了小部件橋接,並遵循了這裏的建議:http://www.erichynds.com/jquery/using-jquery-ui-widget-factory-bridge/(沒有完全理解它的每一部分) 。 你知道,如果在原型上定義函數實際上並不需要嗎? – Danack 2013-02-28 07:14:12
不客氣。查看我的編輯來確定類型。至於你的結構,如果這個對象是一個函數(如果你按照你所關聯的教程,它應該是),那麼使用.prototype是正確的方法,因爲它允許使用'this'關鍵字。此外,如果「getContentInfo」和/或其他函數是常見的,你可能想檢查一下窗口部件中的繼承:http://msdn.microsoft.com/en-us/library/hh404085.aspx#sec25 – 2013-02-28 14:10:01