Struts 2 jQuery插件isSubscribe无法正常工作

编程入门 行业动态 更新时间:2024-10-27 22:21:43
本文介绍了Struts 2 jQuery插件isSubscribe无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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无法正常工作

本文发布于:2023-07-25 09:02:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1208958.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法正常   插件   工作   Struts   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!