我正在创建js树来显示文件夹路径名,而我的问题是如何检查条件,如果数据库表status为0(不活动),则将在js树中显示直通。其他表status刚好恢复正常的状态为1(活动)。下面是我的编码:
<?php
$folderData = mysqli_query($mysql_con,"SELECT * FROM filing_code_management");
$folders_arr = array();
while($row = mysqli_fetch_assoc($folderData)){
$parentid = $row['parentid'];
if($parentid == '0') $parentid = "#";
$selected = false;$opened = false;
if($row['id'] == 2){
$selected = true;$opened = true;
}
$folders_arr[] = array(
"id" => $row['id'],
"parent" => $parentid,
"text" => $row['name'] . ' ' . "<span id='category'>". $row['category']."</span>",
"category" => $row['category'],
"status" => $row['status'], // status 0 is inactive, status 1 is active
"state" => array("selected" => $selected,"opened"=>$opened)
);
}
?>
<script style="text/javascript">
var StrikeNodes = function(nodelist) {
var tree = $('#folder_jstree').jstree(true);
nodelist.forEach(function(n) {
tree.get_node(n.id).a_attr.style = "text-decoration:" + getStrike(parseInt(n.text.substr(0, 3), 10));
tree.redraw_node(n.id); //Redraw tree
StrikeNodes(n.children); //Update leaf nodes
});
};
var getStrike = function(i) {
if (status = '0' ) {
return "line-through;";
} else {
return "";
}
};
$('#folder_jstree').bind('load_node.jstree', function(e, data) {
var tree = $('#folder_jstree').jstree(true);
StrikeNodes(tree.get_json());
});
</script>
现在,我的输出显示了js树中的所有直通,而不是检测哪个是活动的还是非活动的。
我在这里工作的JSFiddle代码:https://jsfiddle.net/ason5861_cs/9x0dsotz/3/
希望有人可以指导我我出错了。
查看您的代码。您没有比较状态,它应该是status == '0'
而不是status = '0'
还有jstree提供的可用选项。 data
选项这可以是您想要的任何东西。它是您要附加到点头的元数据。您以后可以随时访问和修改它-它对节点的外观没有影响。
[{
"id": "1",
"parent": "#",
"text": "100 PENTADBIRAN <span id='category'>JTM<\/span>",
"category": "JTM",
"data": { "status": 0 },
"state": {
"selected": false,
"opened": false
}
}]
var StrikeNodes = function(nodelist) {
var tree = $('#folder_jstree').jstree(true);
nodelist.forEach(function(n) {
tree.get_node(n.id).a_attr.style = "text-decoration:" + getStrike(n.data.status);
tree.redraw_node(n.id); //Redraw tree
StrikeNodes(n.children); //Update leaf nodes
});
};
var getStrike = function(status) {
if (status == 0) {
return "line-through;";
}
return "";
};