简体   繁体   English

jsTree v 3+:如何在制作jsTree时使用JSON格式传递“类型”插件的[类型]信息?

[英]jsTree v 3+ : How to pass [Type] information for the 'Types' plugin using the JSON format in making a jsTree?

I want to create a jsTree(v 3.0.2) using the JSON format on "Populating the tree using JSON" given at http://www.jstree.com/docs/json/ 我想在http://www.jstree.com/docs/json/上给出的“使用JSON填充树”中使用JSON格式创建一个jsTree(v 3.0.2)

// Expected format of the node (there are no required fields)
{
  id          : "string" // will be autogenerated if omitted
  text        : "string" // node text
  icon        : "string" // string for custom
  state       : {
    opened    : boolean  // is the node open
    disabled  : boolean  // is the node disabled
    selected  : boolean  // is the node selected
  },
  children    : []  // array of strings or objects
  li_attr     : {}  // attributes for the generated LI node
  a_attr      : {}  // attributes for the generated A node
}

From the instance, I create my tree using: 从实例中,我使用以下命令创建树:

// create the instance
$('#jstree').jstree({

  "core": {
    "animation": 150,
    "check_callback":true,
    'data': new_data //json object
  },
  "types": {
    "#": {
      "valid_children": ["folder"]
    },
    "folder": {
      "valid_children": ["file"]
    },
    "file": {
      "valid_children": [""]
    }
  },
  "plugins": ["dnd", "search", "wholerow", "types"]
});

I want to make sure that the Folders don't go into other Folders, and the Files don't go into other Files. 我想确保文件夹不会进入其他文件夹,文件不会进入其他文件。 Files go only in Folders. 文件仅在文件夹中。

I want to know how can I pass "type" information in my json object (new_data), so that the types get applied. 我想知道如何在json对象(new_data)中传递“类型”信息,以便应用类型。

I have been able to get the $("#jstree").jstree("set_type", $(this), "file"); 我已经能够获得$("#jstree").jstree("set_type", $(this), "file"); method working, but I do not like the dirty-checking approach. 方法工作,但我不喜欢脏检查方法。 Also, I want the type to be applied IN the JSON , and NOT Externally 此外,我希望类型应用于JSON ,而不是外部

Also, I do not want to use the methods to perform a check while dragging-dropping. 另外,我不想在拖放时使用这些方法来执行检查。 I want the visual cue (see the screenshot below) to appear when it's ok/not ok to drop an element in another place 我想要视觉提示(请参见下面的屏幕截图),当它可以/不能将元素放在另一个地方时出现

出现的视觉提示显示交互模式

For jstree 3.x versions : To answer the first part of your question about how to pass the "type" information in your JSON object, you must declare a type attribute at the same level as the other node attributes like id, text. 对于jstree 3.x版本 :要回答有关如何在JSON对象中传递“类型”信息的问题的第一部分,必须在与其他节点属性(如id,text)相同的级别声明type属性。 For example the updated format of the node will now look like this. 例如,节点的更新格式现在看起来像这样。 Notice the addition of the type attribute. 注意添加了type属性。

// Expected format of the node (there are no required fields)
{
  id          : "string" // will be autogenerated if omitted
  text        : "string" // node text
  icon        : "string" // string for custom
  state       : {
    opened    : boolean  // is the node open
    disabled  : boolean  // is the node disabled
    selected  : boolean  // is the node selected
  },
  children    : []  // array of strings or objects
  li_attr     : {}  // attributes for the generated LI node
  a_attr      : {}  // attributes for the generated A node
  type        : "string"
}

A sample node json representation looks like 示例节点json表示看起来像

{"id":"179356","text":"Node Name 1","state": {"opened":false,"disabled":false,"selected":false},"children":true,"li_attr": {"nodeType":"C","itemId":"12345"},"type":"file"}

This issue is also discussed at the link : https://github.com/vakata/jstree/issues/473 此问题也在以下链接中讨论: https//github.com/vakata/jstree/issues/473

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM