vuejs浏览器查看比例_高度可定制的vuejs树查看器

vuejs浏览器查看比例

VueJS树 (VueJS Tree)

A highly customizable and blazing fast VueJs tree viewer.

高度可定制且快速的VueJs树查看器。

入门 (Getting Started)

安装 (Install)

You can install using yarn:

您可以使用yarn进行安装:

$ yarn add vuejs-tree

or with npm:

或使用npm:

$ npm install vuejs-tree

用法 (Usage)

Add the following lines at the top of your .js file who contain your Vue instance.

在包含您的Vue实例的.js文件顶部添加以下行。

import Tree from 'vuejs-tree'
  Vue.use(Tree)

  // in your vue instance
  methods: {
    getTree: function(treeId) {
      for (var i = 0; i <= this.$children.length - 1; i++) {
        if (this.$children[i].$props.id == treeId) return this.$children[i]
      }
    }
  }

Or add the following lines in your Vue instance.

或在Vue实例中添加以下行。

import Tree from 'vuejs-tree'


  // in your vue instance
  components: {
    'tree': Tree
  },
  methods: {
    getTree: function(treeId) {
      for (var i = 0; i <= this.$children.length - 1; i++) {
        if (this.$children[i].$props.id == treeId) return this.$children[i]
      }
    }
  }

Then add the following line in your html file to generate a tree. You can have as many trees per page as you want.

然后在您的html文件中添加以下行以生成树。 您可以根据需要在每页上拥有任意数量的树。

<tree id="my-tree-id" :custom-options="myCustomOptions" :nodes="treeDisplayData"></tree>

数据结构 (Data Structure)

You need to define data to display which is a nested array of hash.

您需要定义要显示的数据,该数据是哈希的嵌套数组。

Example:

例:

var nodes = [
  {
    text: "Root 1",
    nodes: [
      {
        text: "Child 1",
        nodes: [
          {
            text: "Grandchild 1"
          },
          {
            text: "Grandchild 2"
          }
        ]
      },
      {
        text: "Child 2"
      }
    ]
  },
  {
    text: "Root 2"
  }
];

节点属性 (Node properties)

Here is a fully customized node:

这是一个完全定制的节点:

{
  id: 1,
  text: "Root 1",
  definition: "First node",
  depth: 1,
  checkable: false,
  selectable: false,
  expandable: true,
  disabled: false,
  tags: [42],
  state: {
    checked: false,
    expanded: false,
    selected: false
  },
  nodes: [
    {},
    ...
  ]
}

The Following properties define a node level css and behavior.

以下属性定义节点级别CSS和行为。

ID (id)

String or Integer --> Mandatory

StringInteger -> Mandatory

Used in the tree to differentiate each nodes.

在树中用于区分每个节点。

名称 (name)

String --> Mandatory

String -> Mandatory

The text value displayed at the right of the node icons.

文本值显示在节点图标的右侧。

定义 (definition)

String --> Optional

String -> Optional

If some text is given, then it will show as a tooltip.

如果提供了一些文本,它将显示为工具提示。

深度 (depth)

Integer --> Optional

Integer -> Optional

It correspond to the node depth, starting from 0, 1 or anything. It's advisable to fill theses fields if somes of your nodes have the same id.

它对应于节点深度,从0、1或其他任何值开始。 如果某些节点具有相同的ID,则建议填写这些字段。

残障人士 (disabled)

Boolean --> Optional, default: false

Boolean -> Optionaldefault :false

Used to specifie if the node is disabled or not.

用于指定是否禁用节点。

标签 (tags)

[Integer] --> Optional

[Integer] -> Optional

The tag is displayed at the right end of the line.

标签显示在该行的右端。

可检查的 (checkable)

Boolean --> Optional, default: true

Boolean -> Optionaldefault :true

Used to enable or disable the check event.

用于启用或禁用检查事件。

可选择的 (selectable)

Boolean --> Optional, default: true

Boolean -> Optionaldefault :true

Used to enable or disable the select event.

用于启用或禁用选择事件。

可扩展的 (expandable)

Boolean --> Optional, default: true

Boolean -> Optionaldefault :true

Used to enable or disable the expand event.

用于启用或禁用扩展事件。

(state)
可检查的 (checkable)

Boolean --> Optional, default: true

Boolean -> Optionaldefault :true

Another way to enable or disable the check event.

启用或禁用检查事件的另一种方法。

可选择的 (selectable)

Boolean --> Optional, default: true

Boolean -> Optionaldefault :true

Another way to enable or disable the select event.

启用或禁用选择事件的另一种方法。

可扩展的 (expandable)

Boolean --> Optional, default: true

Boolean -> Optionaldefault :true

Another way to enable or disable the expand event.

启用或禁用扩展事件的另一种方法。

节点 (nodes)

Object --> Optional

Object -> Optional

Used to display node's children. Look above for a structure example

用于显示节点的子代。 在上方查看结构示例

选件 (Options)

Here is an example of a customOptions hash the tree take. I suggest you to use a vuejs computed function if you want to use function pointer. For the icons, it's only compatible with Font Awesome.

这是树采取的customOptions哈希的示例。 如果您要使用函数指针,建议您使用vuejs计算函数。 对于图标,它仅与Font Awesome兼容。

var customOptions = {
  icon: "fa-folder",
  iconColor: "#007AD5",
  selectedIcon: "fa-folder-open",
  selectedIconColor: "#2ECC71",
  addElemIcon: 'fa-plus',
  addElemIconColor: '#007AD5',
  style: {
    tree: 'overflow: hidden; border: none;',
    row: 'background-color: blue;'
  },
  treeEvents: {
    expanded: {
      state: true,
      fn: this.updateNodes
    },
    collapsed: {
      state: true,
      fn: this.updateNodes
    },
    checked: {
      state: true,
      fn: this.updateNodeChecked
    }
  },
  events: {
    selected: {
      state: false,
      fn: null
    },
    editableName: {
      state: true,
      calledEvent: 'expanded'
    }
  }
}
Option namedetail
iconnode folder icon
iconColorfolder's icon color
selectedIconnode's icon when selected
selectedIconColornode icon's color when selected
addElemIconicon to add a node
addElemIconColoradd node icon's color
style
treeoverride default tree css
rowoverride default tree node css
选项名称 详情
图标 节点文件夹图标
iconColor 文件夹的图标颜色
selectedIcon 选中节点的图标
selectedIconColor 选定时节点图标的颜色
addElemIcon 添加节点的图标
addElemIconColor 添加节点图标的颜色
样式
覆盖默认树CSS
覆盖默认树节点CSS

大事记 (Events)

(Tree)

You can call your own function here by assigning a function pointer in the tree options and changing it's state to true. These functions are called after all tree modification.

您可以在此处通过在树选项中分配一个函数指针并将其状态更改为true来调用自己的函数。 在所有树修改之后调用这些函数。

nodeSelected (nodeSelected)

Called when a node is selected. treeOptions.treeEvents.selected.fn

在选择节点时调用。 treeOptions.treeEvents.selected.fn

nodeExpanded && nodeCollapsed (nodeExpanded && nodeCollapsed)

Called when a node is expanded. treeOptions.treeEvents.expanded.fn

扩展节点时调用。 treeOptions.treeEvents.expanded.fn

Called when a node is collapsed. treeOptions.treeEvents.collapsed.fn

节点折叠时调用。 treeOptions.treeEvents.collapsed.fn

nodeChecked (nodeChecked)

Called when a node is collapsed. treeOptions.treeEvents.checked.fn

节点折叠时调用。 treeOptions.treeEvents.checked.fn

树行 (Tree row)

You can call your own function here by assigning a function pointer in the tree options. It will replace the existing behavior of the tree for this event. You can also disabled an event by changing it's state to false.

您可以在此处通过在树选项中分配一个函数指针来调用自己的函数。 它将替换该事件的树的现有行为。 您还可以通过将事件的状态更改为false来禁用事件。

toggleSelected (toggleSelected)

Called when a node is selected. treeOptions.events.selected.fn

在选择节点时调用。 treeOptions.events.selected.fn

toggleExpanded (toggleExpanded)

Called when a node is expanded or collapsed. treeOptions.events.expanded.fn

在节点展开或折叠时调用。 treeOptions.events.expanded.fn

toggleChecked (toggleChecked)

Called when a node is checked. treeOptions.events.checked.fn

在检查节点时调用。 treeOptions.events.checked.fn

editableName (editableName)

You can call a special function who can be used to edit a node, usually with Ajax request, if you assign it's pointer treeOptions.events.editableName.fn Or you can call an existing event by assigining it's name in treeOptions.events.editableName.calledEvent example : treeOptions.events.editableName.calledEvent = 'selected'

如果您为其分配了指针treeOptions.events.editableName.fn ,则可以调用一个特殊函数来编辑节点(通常使用Ajax请求),或者可以通过在treeOptions.events.editableName中使用其名称来调用现有事件treeOptions.events.editableName.calledEvent示例: treeOptions.events.editableName.calledEvent = 'selected'

方法 (Methods)

Methods Params:

方法参数:

depth --> Optionnal but help distinguish nodes with the same id.

depth - > Optionnal但帮助区分具有相同ID的节点。

argWanted --> It can either be a node attribute name (string) or a array of node attribute name (like ['id', 'name']).

argWanted >它可以是节点属性名称(字符串)或节点属性名称的数组(例如['id','name'])。

format --> If you want the function to return an plain array (false) or a hash tree (true).

format ->如果您希望函数返回纯数组(false)或哈希树(true)。

maxDepth --> The function will only access nodes within the maxDepth.

maxDepth >该函数将仅访问maxDepth内的节点。

fullNode --> Return only node ids or node objects.

fullNode >仅返回节点ID或节点对象。

conditions --> It' used to affect only the nodes who match it. For example if the condition is {checked: true}, the function will affect only the nodes who are checked. You can use all nodes attribute that are present in the node object.

conditions ->它仅影响与之匹配的节点。 例如,如果条件为{checked:true},则该函数将仅影响被检查的节点。 您可以使用节点对象中存在的所有节点属性。

checkNode(nodeId,深度) (checkNode(nodeId, depth))

Check a node.

检查节点。

uncheckNode(nodeId,深度) (uncheckNode(nodeId, depth))

Uncheck a node.

取消选中节点。

getSelectedNode() (getSelectedNode())

Return the selected node if you have selected a node.

如果选择了节点,则返回选择的节点。

getCheckedNodes(argWanted,format = false) (getCheckedNodes(argWanted, format = false))

Return all checked nodes.

返回所有检查的节点。

getExpandedNodes(argWanted,format = false) (getExpandedNodes(argWanted, format = false))

Return all expanded nodes.

返回所有展开的节点。

checkAllNodes() (checkAllNodes())

Check all nodes.

检查所有节点。

uncheckAllNodes() (uncheckAllNodes())

Uncheck all nodes.

取消选中所有节点。

expandNode(nodeId,深度) (expandNode(nodeId, depth))

Expand a node.

展开一个节点。

crashNode(nodeId,深度) (collapseNode(nodeId, depth))

Collapse a node.

折叠节点。

selectNode(nodeId,深度) (selectNode(nodeId, depth))

Select a node and deselect the previously selected node if exist.

选择一个节点,然后取消选择先前选择的节点(如果存在)。

expandAllNodes() (expandAllNodes())

Expand all nodes.

展开所有节点。

crashAllNodes() (collapseAllNodes())

Collapse all nodes.

折叠所有节点。

deselectAllNodes() (deselectAllNodes())

Deselect all nodes.

取消选择所有节点。

findNode(nodeId,maxDepth = 9999) (findNode(nodeId, maxDepth = 9999))

Find and return a node.

查找并返回一个节点。

getVisibleNodes(fullNode = false) (getVisibleNodes(fullNode = false))

Get all visible nodes.

获取所有可见节点。

getNodesData(argWanted,条件= {},格式= false) (getNodesData(argWanted, conditions = {}, format = false))

Customizable function that return nodes.

返回节点的可自定义函数。

获取树实例 (Get the tree instance)

If you want to call any tree method, you need to get the instance.

如果要调用任何树方法,则需要获取实例。

For that you just need to call the getTree function and provide your tree id.

为此,您只需要调用getTree函数并提供树id

翻译自: https://vuejsexamples.com/a-highly-customizable-vuejs-tree-viewer/

vuejs浏览器查看比例

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值