gpt4 book ai didi

javascript - 像 ExtJS 一样编程 jQuery UI

转载 作者:数据小太阳 更新时间:2023-10-29 04:17:18 25 4
gpt4 key购买 nike

我正在尝试为 jQuery UI 开发一个抽象层,允许将小部件定义为对象,就像(或类似)ExtJS。这是概念:

var mydialog = new $.ui.dialog({

modal:true,
renderTo:'body',
title:'The Windows Tittle',
content:'The content of the Window'


});

现在我可以说:

mydialog.show();

第一步(我认为)是向 jQuery 添加类创建函数,这允许创建类:

$.MYNAMESPACE.dialog = $.Class ({

constructor:function(){}

//methods and properties

});

真正的问题来了:我必须在前面的类定义中放入什么才能将真实的 $.ui.dialog 与我的链接起来?我的意思是我不想创建一个新的小部件,我只是想重用预定义的 jQuery UI 小部件背后的代码,以便创建一个允许 OOP 和 jQuery UI 的抽象层。

提前致谢

最佳答案

你试过 jquery-ui widget factory 了吗?您可能正在重新发明 wheel.js

slideshow关于你从 widget factory 得到了什么

official splash pageapi

快速了解它在做什么。我想要一个带有一些自定义事件的新对话框

//this is instantiating the widget, does not need to be in the same file
$(function(){
$(".some-selector").miDialog({autoopen:true //because we can});
});
//this is a definition, not an instantiation of the widget. aka,
$.widget("mi.miDialog" //namespace
,$.ui.dialog //inherit from this jquery widget
,//start your widget definition
{ options:{autoopen:false,//overwrite parent default option, while still giving instance option to override our definition's override of parent
someInstanceSafeOption: {why:"not",have:"a",subobject:"option"} },
//underscore functions are 'private' unless you dig into the prototype manually
_create :function(){
//you'll need this function. guaranteed to run once.
// upcoming version call parent create
this._super();
//current version call parent create
$.ui.dialog.prototype._create(this.options);
this.element.addClass("mi-dialog"); //help with custom styling
this._trigger("created"); //trigger custom events
//register for events here, as _create() will only run once per individual instance

},
_init:function(){
//this will run every time someone calls $('some-selector').miDialog();
//i have yet to use it much
},
publicFunction: function(some, params){
//this function does whatever you want, and is called $('some-selector'.miDialog("publicFunction", some,params);
},
_destroy: function(){
//clean up after your widget's create function, if needed.
}

关于javascript - 像 ExtJS 一样编程 jQuery UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14670456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com