How do I apply the following CSS to only the Parent nodes of a Kendo Tree View?

StackOverflow https://stackoverflow.com/questions/18258349

  •  24-06-2022
  •  | 
  •  

Вопрос

I have this CSS class:

.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;
}

And I want to use it on the parent nodes of this Kendo Tree View:

<div id="relationshipsTree"></div>

How do I go about doing this?

EDIT -

This is the .js file I'm using to create the tree. I added:

$('#relationshipsTree').parent().addClass('relationshipsTree');

Based on an answer here, however, it is still not working.

Whole file:

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();
}
Это было полезно?

Решение

Updated

I found that I have misunderstood your question. I think you want to select the DOM parent element while you want to select the parent node in the tree view. This is my updated answer.

Midify your handler a bit:

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

A demo updated here

Другие советы

YOu can use jquery to target the parent of an element.

$('#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',
});
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top