Struts 2 jQuery Subscribe被多次调用 [英] Struts 2 jQuery Subscribe is called more than once
问题描述
在struts 2 jQuery插件中,有一个可用于事件调用的发布/订阅框架.
In the struts 2 jQuery plugin there is a publish/subscribe framework which can be used for event invocation.
考虑此示例....
可以通过订阅onGridCompleteTopics
事件来更改加载网格时的网格行为
One can change the grid behavior when grid is loaded by subscribing too onGridCompleteTopics
event
<sjg:grid id="gridtable" dataType="json"
href="%{url}" gridModel="gridModel" direction="%{pageDir}" width="800"
shrinkToFit="true" onGridCompleteTopics="grid_compelete">
然后在js中:
$.subscribe('grid_compelete', function(event, data) {
//do some thing
}
问题是,如上所述,js和网格位于同一个页面中(它们在一个jsp中),每次我重新加载页面时,都会调用subscribe
,并且subscribe中的代码再次运行.
The problem is that, as above js and the grid are in the same page (they are in one jsp), every time I reload the page the subscribe
is called and the code in the subscribe runs again.
我该如何预防?我在jquery.subscribe.1.2.3
中找到了一个名为isSubscribed
的函数,我认为框架应该在内部使用它来避免此问题.但这不是!
How can I prevent it?! I found a function in jquery.subscribe.1.2.3
which is called isSubscribed
I thought the framework should use it internally to avoid this issue. But it is not!
我也没有找到任何方法来调用和使用此方法.
Also I did not find any way to call and use this method.
推荐答案
$("#gridtable").subscribe('grid_compelete', function(event, data) {
//do some thing
}
或杀死该主题(我自己不喜欢它)
or kill the topic (which I do not prefer it myself)
$.subscribe('grid_compelete', function(event, data) {
//do some thing
$.destroyTopic('grid_compelete');
}
isSubscibe仍然存在并且附加到文档中,请参阅 Struts 2个jQuery插件isSubscribe无法正常运行,以获取@Roman C的完整代码
The isSubscibe is still there and it is attached to document, please see Struts 2 jQuery plugin isSubscribe not working for complete code by @Roman C
这篇关于Struts 2 jQuery Subscribe被多次调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!