jstree:在单击父节点时,只应选择所有子元素并选择父元素。
$('#DivIndustryCategoryTree').on('changed.jstree Event', function(e, data) {
var i, j, r = [];
var relatedIndustryID = [];
categoryBEArray.RelatedIndustries = [];
for (i = 0, j = data.selected.length; i < j; i++) {
var indSelectedObj = {};
indSelectedObj.ProductID = ProductID;
indSelectedObj.ProductPageID = ProductPageID;
indSelectedObj.Language = Language;
r.push(data.instance.get_node(data.selected[i]).text);
indSelectedObj.IndustryID = parseInt(data.instance.get_node(data.selected[i]).id);
relatedIndustryID.push(parseInt(data.instance.get_node(data.selected[i]).id));
categoryBEArray.RelatedIndustries.push(indSelectedObj);
}
selectedData = r;
selectedDataID = relatedIndustryID;
categoryBEArray.RelatedServices.push(null);
categoryBEArray.ID = ProductID;
});
答案 0 :(得分:0)
我不认为通过配置是可能的。但是你可以做的是在迭代所有选定的节点时,在循环开始时检查父(top_selected)节点,并让循环体仅在它为假时运行。
代码:
$('#DivIndustryCategoryTree').on('changed.jstree Event', function(e, data) {
var i, j, r = [];
var relatedIndustryID = [];
categoryBEArray.RelatedIndustries = [];
// add below line
var parentNode = $('#DivIndustryCategoryTree').jstree().get_top_selected(true)[0].text;
//edit below line
for (i = 0, j = data.selected.length; i < j && data.selected[i]).text!= parentNode; i++) {
var indSelectedObj = {};
indSelectedObj.ProductID = ProductID;
indSelectedObj.ProductPageID = ProductPageID;
indSelectedObj.Language = Language;
r.push(data.instance.get_node(data.selected[i]).text);
indSelectedObj.IndustryID = parseInt(data.instance.get_node(data.selected[i]).id);
relatedIndustryID.push(parseInt(data.instance.get_node(data.selected[i]).id));
categoryBEArray.RelatedIndustries.push(indSelectedObj);
}
selectedData = r;
selectedDataID = relatedIndustryID;
categoryBEArray.RelatedServices.push(null);
categoryBEArray.ID = ProductID;
});