久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 Dynatable 插件更新表

Updating table with Dynatable plugin(使用 Dynatable 插件更新表)
本文介紹了使用 Dynatable 插件更新表的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試 dynatable,但遇到了問題.我不知道如何更新來自不同 json 文件的記錄.

Im trying dynatable and Im running into an issue. I not sure how to update records from different json files.

我的 html 正文:

My html body:

<input type="button" value="items a" id="setToItemsA"><br>
<input type="button" value="items b" id="setToItemsB"><br>
<br><br>
<table id="my-final-table">
    <thead>
        <th>Band</th>
        <th>Song</th>
    </thead>
    <tbody>
    </tbody>
</table>

我的腳本

$(document).ready(function() {
    var json1 = [
                  {
                    "band": "Weezer",
                    "song": "El Scorcho"
                  },
                  {
                    "band": "Chevelle",
                    "song": "Family System"
                  }
                ];

    var json2 = [
                  {
                    "band": "Band1",
                    "song": "Song1"
                  },
                  {
                    "band": "Band2",
                    "song": "Song2"
                  }
                ];

    $('#my-final-table').dynatable({
      dataset: {
        records: json1
      }
    });

    $('#setToItemsA').click(
        function() {
            setToItems(json1);
        });
    $('#setToItemsB').click(
        function() {
            setToItems(json2);
        });

    function setToItems (argument) {
        console.log(argument);
        $('#my-final-table').dynatable({
          dataset: {
            records: argument
          }
        });
    }
});

我嘗試取消綁定表并使用新數據集重做,但沒有成功.老實說,我不知道.感謝您的幫助!

I tried to unbind the table and redo it with the new dataset but did not work. I honestly dont know. Thanks for your help!

推薦答案

參見中的相關討論這個 Github 問題.簡短的版本是您要更新 setToItems 函數,以便它

See the relevant discussion in this Github issue. The short version is that you want to update your setToItems function so that it

  1. 替換可動態實例的原始記錄集.
  2. 調用可動態實例的process()函數.

為此,我們先在第一次實例化dynatable時緩存dynatable實例對象(這樣我們就不必在每次調用setToItems函數時一直加載它:

To do this, let's first cache the dynatable instance object when we first instantiate dynatable (so that we don't have to keep loading it every time the setToItems function is called:

var dynatable = $('#my-final-table').dynatable({
  dataset: {
    records: json1
  }
}).data('dynatable');

現在,讓我們更新我們的函數:

Now, let's update our function:

function setToItems (argument) {
  console.log(argument);
  dynatable.settings.dataset.originalRecords = argument;
  dynatable.process();
}

在上面,我們可以將 originalRecords 設置為我們想要的任何 JSON 集合.但是在我們調用 process() 之前,dynatable 不會更新 DOM 中的表.如果我們愿意,這允許我們一次進行多個交互,例如添加一些過濾器、更改頁面、添加排序等,而不會為每個單獨的更改觸發 DOM 更新,除非我們告訴它這樣做.

In the above, we can set the originalRecords to whatever JSON collection we want. But dynatable won't update the table in the DOM until we call process(). This allows us to do multiple interactions at once if we want, such as adding some filters, changing the page, adding sorts, etc. all at once without triggering a DOM update for each individual change unless we tell it to.

這篇關于使用 Dynatable 插件更新表的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

jQuery/JavaScript Library for avatar creation?(用于創建頭像的 jQuery/JavaScript 庫?)
How to do following mask input problem?(如何做以下掩碼輸入問題?)
Issues Setting Value/Label Using DropKick Javascript(使用 DropKick Javascript 設置值/標簽的問題)
how to unit-test private methods in jquery plugins?(如何對 jquery 插件中的私有方法進行單元測試?)
stellar.js - configuring offsets / aligning elements for a vertical scrolling website?(stellar.js - 為垂直滾動網站配置偏移量/對齊元素?)
jQuery masked input plugin. select all content when textbox receives focus(jQuery 屏蔽輸入插件.當文本框獲得焦點時選擇所有內容)
主站蜘蛛池模板: 日韩一区二区免费视频 | 91麻豆精品一区二区三区 | 在线观看免费毛片 | 看片黄全部免费 | 亚洲精选一区 | a毛片大片 | 激情婷婷网 | 天天搞天天搞 | 永久免费看片在线播放 | 日韩精品久久久久久 | 亚洲精品成人网 | 日日干日日| 中文字幕在线观看免费 | 中文字幕av网站 | 韩国av在线 | 国产成人精品亚洲男人的天堂 | 中文字幕第5页 | 日韩av在线免费 | 一级黄视频 | 黄色在线观看免费 | 午夜精品视频在线 | 黄色在线观看免费 | 一区二区福利 | 亚洲精品观看 | 欧美特黄视频 | 97人人插| 国产精品毛片va一区二区三区 | 日日夜夜综合 | 日韩精品免费在线观看 | 久久h| 激情福利视频 | 色综合视频在线观看 | www.四虎.com| 国产精品高潮呻吟av | 午夜美女福利 | 欧美专区在线观看 | 逼逼操 | 51调教丨国产调教视频 | 就爱啪啪网 | 又黄又爽又刺激的视频 | 日韩在线视频观看 |