jQuery UI:如何使用其命名空间调用窗口小部件函数 [英] JQuery UI: How to call a widget function with its namespace

查看:78
本文介绍了jQuery UI:如何使用其命名空间调用窗口小部件函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了两个自定义的JQuery UI小部件,它们具有相同的名称,但具有不同的命名空间,如下所示: 第一个小部件:

I created two custom JQuery UI widgets with same name but with different namespaces as given below: First widget:

$.widget('finance.dialog',{....}); // this was created in the file jquery.finance.dialog.js

第二个小部件:

$.widget('hr.dialog',{.....}); // this was created in the file jquery.hr.dialog.js

除了这两个之外,JQuery UI在名称空间ui中具有自己的对话框小部件(ui.dialog).

Apart from these two, JQuery UI has its own dialog widget (ui.dialog) in the namespace ui.

我的问题是: 当我在如下所示的网页中调用以下内容时,将调用哪个对话框小部件?

My question is: Which dialog widget will be called when i call the following in a web page as given below?

$('div#something').dialog(); 

请注意,我在网页中包含了所有三个小部件变体.

Please note I include all the three widget variants in the web page.

我了解上述情况下存在冲突.我们如何使用其命名空间调用窗口小部件函数,以免发生任何冲突?

I understand there are conflicts in the above scenario. How can we invoke a widget function with its namespace so that there will not be any conflicts?

推荐答案

我有同样的问题,但我认为无法使用命名空间调用jquery ui小部件.

I had the same question, but I don't think it's possible to invoke a jquery ui widget with the namespace.

如果我对此有正确的理解: http://bugs.jqueryui.com/ticket/7489 通过定义具有相同名称的小部件,可以设计成覆盖先前的定义.因为不管名称空间如何,小部件都将其名称映射到$ .fn.

If I understand correctly from this: http://bugs.jqueryui.com/ticket/7489 By defining widgets with the same name, it's by design to overwrite earlier definitions. Because regardless of namespace, the widgets are mapped with their name to $.fn.

如故障单中所建议的那样,您可以使用bridge函数创建到特定命名空间小部件的唯一映射,并使用唯一名称进行调用.

As suggested in the bug ticket you can use the bridge function to create a unique mapping to the specific namespaced widget and call it using the unique name.

在您的情况下,可能是这样的:

In your case, it can be like this:

$.widget.bridge( "finance_dialog", $.finance.dialog );
$.widget.bridge( "hr_dialog", $.hr.dialog );

// then call it with...
$( "div#something" ).hr_dialog(); 

我想另一种方法是首先创建唯一的窗口小部件名称.

I suppose another way would be to create unique widget names in the first place.

这篇关于jQuery UI:如何使用其命名空间调用窗口小部件函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆