我有这样的图片帮助主题:
如果用户选择父主题,我希望用户不能选择父主题(IT、系统和报告问题)或警报警告,用户必须选择测试..或访问问题。像这样的代码:
$(document).ready(function(){
var val = <?php echo Topic::getHelpTopicsTree();?> ;
$('#cc').combotree({
onChange: function (r) {
var c = $('#cc');
var t = c.combotree('tree'); // get tree object
var node = t.tree('getSelected');
var nodeLevel = t.tree('getLevel',node.target);
parentArry = new Array();
var parentArry = new Array();
var parents = getParentArry(t,node,nodeLevel,parentArry);
var parentStr = "";
if(parents.length > 0){
var parentStr = "";
for(var i = 0; i < parents.length; i++){
parentStr += parents[i].text + " / ";
}
}
$('#cc').combotree('setText', parentStr + node.text);
}
});
$('#cc').combotree({
onSelect: function (r) {
//Loads the dynamic form on selection
var data = $(':input[name]', '#dynamic-form').serialize();
$.ajax(
'ajax.php/form/help-topic/' + r.id,
{
data: data,
dataType: 'json',
success: function(json) {
$('#dynamic-form').empty().append(json.html);
$(document.head).append(json.media);
}
});
}
});
$('#cc').combotree('loadData', val);
function getParentArry(tree,selectedNode,nodeLevel,parentArry){
//end condition: level of selected node equals 1, means it's root
if(nodeLevel == 1){
return parentArry;
}else{//if selected node isn't root
nodeLevel -= 1;
//the parent of the node
var parent = $(tree).tree('getParent',selectedNode.target);
//record the parent of selected to a array
parentArry.unshift(parent);
//recursive, to judge whether parent of selected node has more parent
return getParentArry(tree,parent,nodeLevel,parentArry);
}
}
$('#cc').combotree('setText', '— <?php echo __('Select Help Topic'); ?> —');
});
任何帮助表示赞赏。谢谢你。