2

I have a JsTree instance in which all childs are loaded async by a json call.

How can I detect if a user has selected a leaf node?

I've tried to use the success callback of ajax, but of course that also gets called if you simply open a Node with a "+". Is there an event like "child nodes loaded"?

4

1 回答 1

2

拉德克,你是对的。

最后我想出了另一个解决方案。在服务器上请求子节点时,我检测节点是否有子节点。通过向响应 dto 添加一个标志,可以在客户端上使用此信息,如下所示:

success: function (data) { 
  return $.map(data.d, function (item) {
    if(item.HasChildren)
      return {
          data: item.data,
          state: item.state,
          attr: item.attr,
          children: item.children
      };
      else
          return {
          data: item.data,
          attr: item.attr
      };
  })
}

如果响应中没有“children”和“state”属性,jsTree 会将其识别为叶节点。现在可以在“node_select”中使用jsTree的.is_leaf(node)方法了。

于 2012-05-31T13:32:22.957 回答