title: Tree_view undefined after read kendo tree
body: <p>Here's my problem:</p>
  
  <p>I load a first time my tree to display him.
  I can change the value of the Session's files name "state" to enable or disable a node in my tree.</p>
  
  <p>But after I change ne value in my database and return the JSON, I read again the tree to refresh my tree with the changes but it's failed and write in console :
  " TypeError: Tree_view.getElementsByClassName(...)[0].children[(item.id_perso - 1)].children[1] is undefined".</p>
  
  <p>That I don't understand is I pass my first time by these functions and it work well, but when I reload it failed apparently because the it undefined.</p>
  
  <p>Thank's for any help.</p>
  
  <pre><code>    $(document).ready(function() {
      $('#Tree_view').kendoTreeView({
          template: "#= item.name #",
          dataSource: Parcours,
          dataTextField: 'name',
          loadOnDemand: true,
          expand: onExpandedItem
      });
  });
  
  function onExpandedItem(e) {
  
      var id_user = @Model.id;
  
      var item =  $('#Tree_view').data('kendoTreeView').dataItem(e.node);
      var treeview = $('#Tree_view').data('kendoTreeView');
      var type = item.fields.type;
  
      if (item.level() &gt; 0) {
          item.id_parcours = item.parentNode().id_parcours;
          if (item.level() == 2) {
              item.id_promo = item.parentNode().id;
          }
      }
      else item.id_parcours = item.Id;
  
      switch (type) {
          case 'parcours':
              item.children.transport.options.read = {
                  url: '@Url.Action("Get_Session", "Users")' + '?user_id=' + id_user,
                  dataType: "json",
              };
              break;
  
          case 'session':
              item.children.transport.options.read = {
                  url: '@Url.Action("Get_Matiere")' + '?user_id=' + id_user,
                  dataType: "json"
              };
              break;
  
          default:
              break;
      }
  
      if (item.level() == 0) {
          setTimeout(function() { waitDisable(item, treeview); }, 1000);
      }
  }
  
  function waitDisable(item, treeview) {
      if (item.fields.type == "parcours")
      {
          var node = Tree_view.getElementsByClassName('k-group')[0].children[item.id_perso - 1].children[1].children;
          for (i = 0; i &lt; item.children._data.length; i ++)
          {
              if (item.children._data[i].state != null) {
                  node[i].children[0].children[1].className = "k-in k-state-disabled";
                  node[i].children[0].children[0].className = ".k-icon-remove";
              }
              else node[i].children[0].children[0].className = "k-icon k-plus";
  
              addRow(node, item, i, treeview);
          }
      }
  }
  
  var cmp = 0;
  var One_Time = false;
  
  function addRow(node_Here, item, i, treeview) {
  
      var actual_row = node_Here[i].children[0];
      if (actual_row.childNodes.length &lt; 3) {
          var newSpan = document.createElement('button');
          if (item.children._data[i]._childrenOptions.data.state != null) {
              newSpan.appendChild(document.createTextNode("Re-Up"));
              newSpan.className = "change_state btn btn-success btn-xs";
          }
          else {
              newSpan.appendChild(document.createTextNode("Down"));
              newSpan.className = "change_state btn btn-danger btn-xs";
          }
          actual_row.appendChild(newSpan);
      }
      cmp += 1;
      if (cmp == item.children._data.length)
          One_Time = true;
      if (One_Time) {
          addClickListner(item, i, treeview);
          One_Time = false;
          cmp = 0;
      }
  }
  
  function addClickListner(item, i, treeview) {
      $(".change_state").click(function (event) {
          var name_Promo_Rm = event.target.parentNode.children[1].textContent;
          var User_Select = event.view.Parcours.transport.read.data.user_id;
          $.ajax({
              url: '@Url.Action("ChangeStatutBase", "Users")',
              type: 'GET',
              dataType: 'json',
              data: { Name_Promo: name_Promo_Rm, User_id: User_Select },
          });
          refreshTree(treeview);
      })
  }
  
  // Refresh tree
  function refreshTree(treeview) {
      // Save open items
      saveExpandedItems(treeview);
      // Reload data source
      treeview.dataSource.read();
      // Load open items
      console.log("OKKKKKKK");
      setTimeout(loadExpandedItems(), 600);
  
  }
  </code></pre>