JS等待数据台服务数据加载

发布于 2025-02-06 20:58:02 字数 1352 浏览 2 评论 0原文

我有一个用于加载数据的表,并且编写了一个代码,该代码将每个表分配给HREF带有JavaScript,因为启用了Serveride,我无法为每个TD分配HREF。因此,每个时间页面都会更改或调用搜索查询,我需要将HREF分配给客户端边表行。

这是我到目前为止所说的:

function assign_href_to_tables() {
console.log("Run assign_href_to_tables");
   // access all td variables when serverside enabled.
  $('#table').on( 'order.dt', function () {
      var table_rows = $('#table').find('tbody tr');
      console.log(table_rows)
      // scan through table rows and assign onclick event to each row.
      table_rows.each(function(index, element) {
        $(this).click(function() {
          var id = $(this).find('td:nth-child(1)').text();
          // reidrect to the edit page with the id of the clicked row
          window.document.location = '/detail/' + id;
        });
      });
    } );

  
}

我调用nistion_href_to_tablesinitcomplete eg中的功能:

"initComplete": function( settings, json ) {
        assign_href_to_tables();
      },

如果我在文档上调用函数,则只会影响首页。当页面更改或搜索请求时,请查询HREF停止工作。

我试图跟随此 link 但是我不明白它,也无法实施它。

只要我理解,问题出现initcomplete就不会等待表数据加载。我不知道我的工作缺少什么。谢谢。

I have a table for loading data and i wrote a code which assigns each table an href with javascript since the serverside enabled i can't assign each td a href. Therefore, each time page changes or search query invoked i need to assign href to client side table rows.

Here is what i put so far:

function assign_href_to_tables() {
console.log("Run assign_href_to_tables");
   // access all td variables when serverside enabled.
  $('#table').on( 'order.dt', function () {
      var table_rows = $('#table').find('tbody tr');
      console.log(table_rows)
      // scan through table rows and assign onclick event to each row.
      table_rows.each(function(index, element) {
        $(this).click(function() {
          var id = $(this).find('td:nth-child(1)').text();
          // reidrect to the edit page with the id of the clicked row
          window.document.location = '/detail/' + id;
        });
      });
    } );

  
}

I invoke the assign_href_to_tables function in initComplete e.g.:

"initComplete": function( settings, json ) {
        assign_href_to_tables();
      },

If i call the function on document ready it will affect only the first page. When page changes or search request queried href stops working.

I tried to follow this link but i did not understand it nor i could implement it.

As long as i understand, the problem arise initComplete does not wait for the table data to load. I don't know what is missing in my work. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文