DynaTable - 将数据集记录更新为新数据集

DynaTable - Update the dataset records to new data set

我有这个:我的模型:

function MyModel(title, status, user, lastUpdated, local_id) {
    this.title = title;
    this.status = status;
    this.reported_by = { username: user };
    this.utc_last_updated = lastUpdated;
    this.local_id = local_id;
    return this;
}

而且,我有这个 render_and_update() 函数:

function render_and_update(owner, newList, callBack){

    function tbodyWriter(id, MyModel) {

      var tRow = '<tr class="example-row"><th class="local-id">' + MyModel.local_id 
        + '</th><th class="title">' + MyModel.title +'</th><th class="status">'
        +MyModel.status +'</th><th class="reported-by">' + MyModel.reported_by.username 
        + '</th><th class="last-updated">' + MyModel.utc_lastUpdated + '</th><th class="display-none">' 
        + MyModel.utc_lastUpdated.getTime() + '</th></tr>';
      return tRow;

    }

    $('table-collection').dynatable({
        dataset: {
            records: newList,
            perPageDefault: 10,
            perPageOptions: [5, 10, 20]
        },
        writers: {
            _rowWriter: tbodyWriter
        }
    });
    callBack();
}


function MainController() {
    getUpdatedData(function(owner, updatedData) { /* make ajax call & returns updated records list on success*/
        render_and_update(owner, updatedData, function() { /* function having problem */
            console.log('end..');
        });
    });
}

$('my-button').click(MainController);

问题是:当我单击按钮时,它会调用 render_and_update() 函数,并且第一次插入记录集但在第二次单击时它不会将数据集更新为新数据集...

为什么 DOM 没有更新?

谢谢。

我自己解决了这个问题..

解决了我的问题:

if(clicked) {
     dynatable.settings.dataset.originalRecords = issuesList;
     dynatable.process();
}

更新了 update_and_render() 函数和 MainController() 函数:

function render_and_update(clicked, owner, newList, callBack){

    function tbodyWriter(id, MyModel) {

      /* Nothing changed in this function. i.e., same as above in question. */

    }

    var dynatable = $('table-collection').dynatable({
        dataset: {
            records: newList,
            perPageDefault: 10,
            perPageOptions: [5, 10, 20]
        },
        writers: {
            _rowWriter: tbodyWriter
        }
    }).data('dynatable');

    if(clicked) {
        dynatable.settings.dataset.originalRecords = issuesList;
        dynatable.process();
    }

    callBack();
}

function MainController() {
    getUpdatedData(function(owner, updatedData) { /* make ajax call & returns updated records list on success*/
        render_and_update(true, owner, updatedData, function() { /* function having problem */
            console.log('end..');
        });
    });
}

希望这对以后的其他人有帮助!