【发布时间】:2014-01-02 20:20:04
【问题描述】:
我正在尝试 dynatable,但遇到了问题。我不知道如何更新来自不同 json 文件的记录。
我的 html 正文:
<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
}
});
}
});
我尝试取消绑定表并使用新数据集重做,但没有成功。老实说,我不知道。感谢您的帮助!
【问题讨论】:
标签: jquery html jquery-plugins dynatable