struts 2 jQuery插件有一个内置的发布 / 订阅框架。
The struts 2 jQuery plugin has a built in publish/subscribe framework.
如果您定义自己的发布和订阅事件(例如在网格上),则每次发布事件时都会调用订阅的函数。有关详细信息,请参阅( Struts 2 jQuery Subscribe不止一次调用)
If you define your own publish and subscribe event (for example on a grid) the subscribed function will be called every time the event is published. For details please see (Struts 2 jQuery Subscribe is called more than once)
为了防止这种情况,可以使用 isSubscribed 方法。
To prevent this, there is a isSubscribed method which can be used.
对于网格:
<sjg:grid id="gridtable" onBeforeTopics="before_grid_load" >JS将是:
$.subscribe('before_grid_load', function(event, data) { if ( $('#gridtable').isSubscribed('before_grid_load') ){ return ; } //go on with function }问题是 $('#gridtable')。isSubscribed('before_grid_load')返回 false 每次!
推荐答案在元素上应用函数 isSubscribed $('#gridtable')但订阅 $(文件)。我已经测试了最后一个元素,它对我不起作用。但尝试使用第一个元素并且它有效。
The function isSubscribed is applied on the element $('#gridtable') but subscribed to the $(document). I have tested with the last element and it didn't work to me. But tried with the first element and it worked.
脚本:
<head> <link href="<s:url value="/css/template_styles.css"/>" type="text/css" rel="stylesheet"> <sj:head /> <title>jQuery Grid</title> <script type="text/javascript"> $(document).ready(function(){ console.log("Before subscribe"); $("#gridtable").subscribe("beforeTopic", function(topic, data) { console.log('Topic: '+data, topic); if ( $("#gridtable").isSubscribed("beforeTopic") ){ console.log('Subscribed: '+data, topic); return; } //go on with function console.log('Not subscribed: '+data, topic); }); console.log("After subscribe"); }); </script> </head>对于网格:
<sjg:grid id="gridtable" onBeforeTopics="beforeTopic" >更多推荐
Struts 2 jQuery插件isSubscribe无法正常工作
发布评论