【问题标题】:How to execute jquery call on data returned with jquery $.post call如何对使用 jquery $.post 调用返回的数据执行 jquery 调用
【发布时间】:2011-02-16 14:57:14
【问题描述】:

我有一个页面使用jquery将html表转换为使用jquery treeTable插件的文件结构。html表在一个名为“treeStructure”的div中

我可以将新文件夹添加到树中的任何文件夹中,并且我使用 post call 将新文件夹添加到数据库中。该帖子返回一个新的 html 表,其中包含添加的文件夹,并将“treeStructure” div 的内容替换为返回的数据。然后我想使用 jquery 将该表再次转换为文件结构(就像我在 $document.ready() 中所做的那样),而不刷新页面。

我想我需要使用 Jquery 的 .live() 功能,但我不知道该怎么做。

【问题讨论】:

    标签: jquery post tree-structure


    【解决方案1】:

    在对您的$.post 调用的回调中,您可以对返回的数据运行插件。

    $.post('some/path', {some:'data'}, function( resp ) {
           // create a jQuery object with the response
         var $resp = $(resp);
           // call the plugin
         $resp.treeTable();
           // append the result
         $resp.appendTo('wherever');
    });
    

    如果表格在响应中嵌套得更深,您需要进行查找:

    $resp.find('#myTable').treeTable();
    

    【讨论】:

      【解决方案2】:

      如果您只需要为尚不存在的元素注册事件处理程序,请替换

      $('selector').click(function(e) { /* your code */ });
      

      $('selector').live('click', function(e) { /* your code */ });
      

      【讨论】:

      • 这适用于事件处理程序,但似乎 OP 正在询问是否运行插件。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多