[英]dynamically add rows to jquery treetable *not at root*
I'm using the treetable plugin and I want to dynamically load some rows of data from a Taffy db previously populated from an xml file. 我正在使用treetable插件,我想从以前从xml文件填充的Taffy数据库中动态加载一些数据行。 I've verified that loadBranch works fine on the root of the table using "null" as the node but I can't seem to make it child of the first row.
我已经验证了loadBranch在表的根上运行正常,使用“null”作为节点,但我似乎无法使它成为第一行的子代。
HTML: HTML:
<table id='data_tree'>
<tr class="branch" data-tt-id="1">
<td>Studies</td>
</tr>
</table>
Javascript: 使用Javascript:
$(window).load(function(){
studies_db().each( function (record,recordnumber) {
$("#data_tree").treetable("loadBranch",1,
"<tr>"+
"<td><b>Accession:</b> "+record.accession+"<br>"+
"<b>Title:</b> "+record.title+"<br>"+
"<b>Authors:</b> "+record.authors+"<br>"+
"<b>Release date: </b>"+record.date+"<br>"+
"<b>Number of markers: </b>"+record.samples+"<br>"+
"</td></tr>")
});
});
The loadBranch
function expects a Node object, not a node identifier. loadBranch
函数需要Node对象,而不是节点标识符。 Try this instead: 试试这个:
$(window).load(function(){
studies_db().each( function (record,recordnumber) {
var node = $("#data_tree").treetable("node", "1");
$("#data_tree").treetable("loadBranch", node,
"<tr data-tt-id='2'>"+
"<td><b>Accession:</b> "+record.accession+"<br>"+
"<b>Title:</b> "+record.title+"<br>"+
"<b>Authors:</b> "+record.authors+"<br>"+
"<b>Release date: </b>"+record.date+"<br>"+
"<b>Number of markers: </b>"+record.samples+"<br>"+
"</td></tr>");
});
});
Note that I've also added a data-tt-id attribute to the tr, otherwise the treetable plugin will complain. 请注意,我还在tr中添加了data-tt-id属性,否则treetable插件会抱怨。
I have to admit that it is confusing that some functions expect a node identifier and others a Node
object... This is something that should be streamlined in the future. 我不得不承认,有些功能需要一个节点标识符而其他功能需要一个
Node
对象,这是令人困惑的......这是将来应该简化的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.