@a.abunada/vue-jstree-rtl 中文文档教程

发布于 4年前 浏览 24 项目主页 更新于 3年前

vue-jstree-rtl

npm

Introduction

vue2 RTL 的树插件

NPM

    npm install vue-jstree-trl

ES6

    import VJstree from 'vue-jstree-rtl'

    new Vue({
      components: {
        VJstree
      }
    })

Setup

    npm install
    npm run dev

Usage

    <v-jstree :data="data" size="large" show-checkbox multiple allow-batch whole-row @item-click="itemClick"></v-jstree>

    new Vue({
      data: {
        data: [
          {
            "text": "Same but with checkboxes",
            "children": [
              {
                "text": "initially selected",
                "selected": true
              },
              {
                "text": "custom icon",
                "icon": "fa fa-warning icon-state-danger"
              },
              {
                "text": "initially open",
                "icon": "fa fa-folder icon-state-default",
                "opened": true,
                "children": [
                  {
                    "text": "Another node"
                  }
                ]
              },
              {
                "text": "custom icon",
                "icon": "fa fa-warning icon-state-warning"
              },
              {
                "text": "disabled node",
                "icon": "fa fa-check icon-state-success",
                "disabled": true
              }
            ]
          },
          {
            "text": "Same but with checkboxes",
            "opened": true,
            "children": [
              {
                "text": "initially selected",
                "selected": true
              },
              {
                "text": "custom icon",
                "icon": "fa fa-warning icon-state-danger"
              },
              {
                "text": "initially open",
                "icon": "fa fa-folder icon-state-default",
                "opened": true,
                "children": [
                  {
                    "text": "Another node"
                  }
                ]
              },
              {
                "text": "custom icon",
                "icon": "fa fa-warning icon-state-warning"
              },
              {
                "text": "disabled node",
                "icon": "fa fa-check icon-state-success",
                "disabled": true
              }
            ]
          },
          {
            "text": "And wholerow selection"
          }
        ]
      },
      methods: {
        itemClick (node) {
          console.log(node.model.text + ' clicked !')
        }
      }
    })

API

PropsTypeDefaultDescribe
dataArrayset tree data
sizeStringset tree item size , value : 'large' or '' or ''small'
show-checkboxBooleanfalseset it show checkbox
allow-transitionBooleantrueallow use transition animation
whole-rowBooleanfalseuse whole row state
no-dotsBooleanfalseshow or hide dots
collapseBooleanfalseset all tree item collapse state
multipleBooleanfalseset multiple selected tree item
allow-batchBooleanfalsein multiple choices. allow batch select
text-field-nameString'text'set tree item display field
value-field-nameString'value'set tree item value field
children-field-nameString'children'set tree item children field
item-eventsObject{}register any event to tree item, example
asyncFunctionasync load callback function , if node is a leaf ,you can set 'isLeaf: true' in data
loading-textString'Loading'set loading text
draggableBooleanfalseset tree item can be dragged , selective drag and drop can set 'dragDisabled: true' and 'dropDisabled: true' , all default value is 'false'
drag-over-background-colorString'#C9FDC9'set drag over background color
klassStringset append tree class

Methods in node.model

MethodParams
addChild(object) newDataItem
addAfter(object) newDataItem, (object) selectedNode
addBefore(object) newDataItem, (object) selectedNode
openChildren
closeChildren

Event

@item-click(node,项目,e)

@item-toggle(节点,项目,e)

@item-drag-start(节点,项目,e)

@项目拖动结束(节点,项目,e)

@item-drop-before(节点,项目,draggedItem,e)

@item-drop(节点,项目, draggedItem, e)

node : 当前节点vue对象

item : 当前节点数据项对象

e : 事件

Data Item Optional Properties

NameTypeDefaultDescribe
iconStringcustom icon css class
openedBooleanfalseset leaf opened
selectedBooleanfalseset node selected
disabledBooleanfalseset node disabled
isLeafBooleanfalseif node is a leaf , set true can hide '+'
dragDisabledBooleanfalseselective drag
dropDisabledBooleanfalseselective drop

Custom Item Example

<v-jstree :data="data">
  <template scope="_">
    <div style="display: inherit; width: 200px" @click.ctrl="customItemClickWithCtrl">
      <i :class="_.vm.themeIconClasses" role="presentation" v-if="!_.model.loading"></i>
      {{_.model.text}}
      <button style="border: 0px; background-color: transparent; cursor: pointer;" @click="customItemClick(_.vm, _.model, $event)"><i class="fa fa-remove"></i></button>
    </div>
  </template>
</v-jstree>

更优雅:

<v-jstree :data="data">
  <template scope="_">
    <div style="display: inherit; width: 200px" @click.ctrl="customItemClickWithCtrl" @click.exact="customItemClick(_.vm, _.model, $event)">
    <i :class="_.vm.themeIconClasses" role="presentation" v-if="!_.model.loading"></i>
    {{_.model.text}}
    </div>
  </template>
</v-jstree>

scopevue@2.5.0+ 中被替换,超过 vue@2.5.0+ 使用 slot-scope

License

许可根据 MIT 许可证

感谢 jstree 的用户界面

vue-jstree-rtl

npm

Introduction

A tree plugin for vue2 RTL

NPM

    npm install vue-jstree-trl

ES6

    import VJstree from 'vue-jstree-rtl'

    new Vue({
      components: {
        VJstree
      }
    })

Setup

    npm install
    npm run dev

Usage

    <v-jstree :data="data" size="large" show-checkbox multiple allow-batch whole-row @item-click="itemClick"></v-jstree>

    new Vue({
      data: {
        data: [
          {
            "text": "Same but with checkboxes",
            "children": [
              {
                "text": "initially selected",
                "selected": true
              },
              {
                "text": "custom icon",
                "icon": "fa fa-warning icon-state-danger"
              },
              {
                "text": "initially open",
                "icon": "fa fa-folder icon-state-default",
                "opened": true,
                "children": [
                  {
                    "text": "Another node"
                  }
                ]
              },
              {
                "text": "custom icon",
                "icon": "fa fa-warning icon-state-warning"
              },
              {
                "text": "disabled node",
                "icon": "fa fa-check icon-state-success",
                "disabled": true
              }
            ]
          },
          {
            "text": "Same but with checkboxes",
            "opened": true,
            "children": [
              {
                "text": "initially selected",
                "selected": true
              },
              {
                "text": "custom icon",
                "icon": "fa fa-warning icon-state-danger"
              },
              {
                "text": "initially open",
                "icon": "fa fa-folder icon-state-default",
                "opened": true,
                "children": [
                  {
                    "text": "Another node"
                  }
                ]
              },
              {
                "text": "custom icon",
                "icon": "fa fa-warning icon-state-warning"
              },
              {
                "text": "disabled node",
                "icon": "fa fa-check icon-state-success",
                "disabled": true
              }
            ]
          },
          {
            "text": "And wholerow selection"
          }
        ]
      },
      methods: {
        itemClick (node) {
          console.log(node.model.text + ' clicked !')
        }
      }
    })

API

PropsTypeDefaultDescribe
dataArrayset tree data
sizeStringset tree item size , value : 'large' or '' or ''small'
show-checkboxBooleanfalseset it show checkbox
allow-transitionBooleantrueallow use transition animation
whole-rowBooleanfalseuse whole row state
no-dotsBooleanfalseshow or hide dots
collapseBooleanfalseset all tree item collapse state
multipleBooleanfalseset multiple selected tree item
allow-batchBooleanfalsein multiple choices. allow batch select
text-field-nameString'text'set tree item display field
value-field-nameString'value'set tree item value field
children-field-nameString'children'set tree item children field
item-eventsObject{}register any event to tree item, example
asyncFunctionasync load callback function , if node is a leaf ,you can set 'isLeaf: true' in data
loading-textString'Loading'set loading text
draggableBooleanfalseset tree item can be dragged , selective drag and drop can set 'dragDisabled: true' and 'dropDisabled: true' , all default value is 'false'
drag-over-background-colorString'#C9FDC9'set drag over background color
klassStringset append tree class

Methods in node.model

MethodParams
addChild(object) newDataItem
addAfter(object) newDataItem, (object) selectedNode
addBefore(object) newDataItem, (object) selectedNode
openChildren
closeChildren

Event

@item-click(node, item, e)

@item-toggle(node, item, e)

@item-drag-start(node, item, e)

@item-drag-end(node, item, e)

@item-drop-before(node, item, draggedItem, e)

@item-drop(node, item, draggedItem, e)

node : current node vue object

item : current node data item object

e : event

Data Item Optional Properties

NameTypeDefaultDescribe
iconStringcustom icon css class
openedBooleanfalseset leaf opened
selectedBooleanfalseset node selected
disabledBooleanfalseset node disabled
isLeafBooleanfalseif node is a leaf , set true can hide '+'
dragDisabledBooleanfalseselective drag
dropDisabledBooleanfalseselective drop

Custom Item Example

<v-jstree :data="data">
  <template scope="_">
    <div style="display: inherit; width: 200px" @click.ctrl="customItemClickWithCtrl">
      <i :class="_.vm.themeIconClasses" role="presentation" v-if="!_.model.loading"></i>
      {{_.model.text}}
      <button style="border: 0px; background-color: transparent; cursor: pointer;" @click="customItemClick(_.vm, _.model, $event)"><i class="fa fa-remove"></i></button>
    </div>
  </template>
</v-jstree>

more elegant:

<v-jstree :data="data">
  <template scope="_">
    <div style="display: inherit; width: 200px" @click.ctrl="customItemClickWithCtrl" @click.exact="customItemClick(_.vm, _.model, $event)">
    <i :class="_.vm.themeIconClasses" role="presentation" v-if="!_.model.loading"></i>
    {{_.model.text}}
    </div>
  </template>
</v-jstree>

scope be replaced in the vue@2.5.0+ , over vue@2.5.0+ use slot-scope

License

Licensed under the MIT license.

Thanks For jstree's UI

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文