我有这个CSS类:
.relationshipsTree
{
display: inline;
font-size: 10pt;
text-decoration: none;
/*cursor: hand;*/
overflow: hidden;
overflow-x: hidden;
overflow-y: hidden;
filter: none;
font-weight: bold;
color: green;
background-color: transparent;
}
我想在这个剑道树视图的父节点上使用它:
<div id="relationshipsTree"></div>
我该怎么做?
编辑 -
这是我用来创建树的.js文件。我补充说:
$('#relationshipsTree').parent().addClass('relationshipsTree');
然而,基于这里的答案,它仍然无效。
整个文件:
function CreateRelationshipsTree()
{
var primaryContactId = 671;
var personOrCompany = 'C';
var rootMemberId = 0;
var data = new kendo.data.HierarchicalDataSource({
transport: {
read: {
url: "../api/relationships?primaryContactId=" + primaryContactId + "&personOrCompany=" + personOrCompany + "&rootMemberId=" + rootMemberId,
contentType: "application/json"
}
},
schema: {
model: {
hasChildren: "hasChildren",
children: "Items"
}
}
});
$("#relationshipsTree").kendoTreeView({
dataSource: data,
loadOnDemand: true,
dataUrlField: "LinksTo",
dataTextField: ["Name", "Name"],
select: treeviewSelect
});
function treeviewSelect(e) {
var node = this.dataItem(e.node);
window.open(node.NotificationLink, "_self");
}
$('#relationshipsTree').parent().addClass('relationshipsTree');
}
function RefreshProjectTree() {
var treeView = $("#relationshipsTree").data("kendoTreeView");
treeView.dataSource.read();
}
答案 0 :(得分:1)
我发现我误解了你的问题。我想您想要在树视图中选择父节点时选择 DOM 父元素。这是我更新的答案。
稍微改善你的处理程序:
function treeviewSelect(e) {
$('#relationshipsTree div').removeClass('relationshipsTree');
$(e.node).parents('li').first().children('div').addClass('relationshipsTree');
var node = this.dataItem(e.node);
window.open(node.NotificationLink, "_self");
}
演示已更新here
答案 1 :(得分:0)
你可以使用jquery来定位一个元素的父元素。
$('#youselector').parent().css({
display:'inline',
font-size:'10pt',
text-decoration:'none',
overflow:'hidden',
overflow-x:'hidden',
overflow-y:'hidden',
filter:'none',
font-weight:'bold',
color:'green',
background-color:'transparent',
});