1

我有这个 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();
}
4

2 回答 2

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");
  
}

此处更新的演示

于 2013-08-15T17:46:44.350 回答
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',
});
于 2013-08-15T17:42:26.547 回答