JsTree v 3+: How to pass [Type] infromation for the "Types" plugin using the JSON format when creating jsTree?

I want to create jsTree (st 3.0.2) using the JSON format on "Filling the tree using JSON" given at http://www.jstree.com/docs/json/

// 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 are not in other folders and the files are not in other files. Files go only in folders.

I want to know how to pass type information to my json object (new_data) so that the types are applied.

I managed to get a method $("#jstree").jstree("set_type", $(this), "file");, but I don't like the dirty check approach. Also, I want the type to be applied in JSON and NOT outside

, . , (. ) , / .

Visual cue appearing showing the interaction pattern

+4
1

jstree 3.x. , "type" JSON, , node, id, text. , node . 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"
}

node json

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

: https://github.com/vakata/jstree/issues/473

+1

Source: https://habr.com/ru/post/1547649/


All Articles