Struts 2 jQuery插件isSubscribe无法正常工作 [英] Struts 2 jQuery plugin isSubscribe not working

查看:225
本文介绍了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无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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