0
作爲從jQuery 1.6.4升級到1.9.x的一部分,我試圖理解如何使用jQuery小部件橋來允許訪問作爲獨立創建的小部件的函數對象,而不是作爲jQuery的擴展。在基於非函數的對象上的jQuery小部件橋
所有示例(like this one)都使用原型函數作爲對象的源定義,該對象的源定義似乎沒有映射爲直接從基於定義的對象定義對象。
比如我定義窗口小部件是這樣的:
var ControlPanel = {
instance: null,
options: {
//Some options here
},
simpleFunction: function(){
alert("I am a function");
},
_init: function() {
//Some init stuff here
}
}
$.widget("basereality.controlPanel", ControlPanel); // create the widget
//This doesn't appear to work...
$.widget.bridge('controlPanel', $.basereality.controlPanel); //'Bridge' the widget
然後做創建它的一個實例:
var controlPanelParams = {
// some options go here
};
var newControlPanel = $('#controlPanel').controlPanel(controlPanelParams);
我現在想能夠調用的方法「 simpleFunction',我試着去做:
newControlPanel.simpleFunction();
//and
$(newControlPanel).simpleFunction();
兩者都是g一個'對象沒有叫做simpleFunction'的方法錯誤。
那麼我在做什麼錯了,你打算如何在基於非函數的對象上使用$ .widget.bridge?