the*_*eme 9 jquery datatables backbone.js
我正在努力将backbone.js与dataTables集成.
我在这里有一个jsfiddle:http://jsfiddle.net/mwagner72/ekgZk/17/
到目前为止,我认为我最接近这个设置:
var Chapter = Backbone.Model;
var chapters = new Backbone.Collection();
chapters.add(new Chapter({ page: 9, title: "The End" }));
chapters.add(new Chapter({ page: 5, title: "The Middle" }));
chapters.add(new Chapter({ page: 1, title: "The Beginning" }));
$('#table_id_3').dataTable({
"aoColumns": [
{"sTitle": "Title", "mDataProp": "title"},
{"sTitle": "Page #","mDataProp": "page"}],
sAjaxSource: "",
sAjaxDataProp: "",
fnServerData: function(sSource, aoData, fnCallback) {
console.log('here we go');
fnCallback(chapters.toJSON());
}
});
Run Code Online (Sandbox Code Playgroud)
这是使用我的集合作为我的dataTable的数据源.
我的问题:
如何告诉dataTables检查集合中的更新数据?
the*_*eme 14
所以我在alqu的帮助下在jquery dataTables网站上找到了答案.诀窍是使用fnReloadAjax(),它将再次基于集合重绘您的数据表.
$('#table_id_3').dataTable({
"aoColumns": [
{ "sTitle": "Title", "mDataProp": "title" },
{ "sTitle": "Page #", "mDataProp": "page" }],
sAjaxSource: "",
sAjaxDataProp: "",
fnServerData: function( sSource, aoData, fnCallback ){
console.log(chapters.toJSON());
fnCallback(chapters.toJSON());
}
});
chapters.add(new Chapter({page: 4, title: "The next bunny"}));
var oTable3 = $('#table_id_3').dataTable();
oTable3.fnReloadAjax();
Run Code Online (Sandbox Code Playgroud)
我在这里有一个jsfiddle:http://jsfiddle.net/mwagner72/ekgZk/