Giter Site home page Giter Site logo

ztree-for-react's Introduction

ztree-for-react

Build Status DUB

对jQuery zTreeV3.x 插件做react封装

install

npm install ztree-for-react --save-dev

useage

import React,{Component} from 'react';
import ReactZtree from 'ztree-for-react';
const nodes= [
	{name: "父节点1",
    id:0,
     children: [
		{name: "子节点1",
    id:1},
		{name: "子节点2",id:2,children:[
      {name:"子节点3",id:3}
    ]}
	]}
];
export default class App extends Component {
  render() {
    return (
      <div>
          <ReactZtree nodes={nodes} events={this.getEvents()} check={check} ref="ztree" treeName={'tree1'}/>
          <ReactZtree nodes={nodes} events={this.getEvents()} check={check} ref="ztree"/>
      </div>
    );
  }
  getEvents(){
    return {
      'onClick':(event,treeId,treeNode)=>{this.handleClick(event,treeId,treeNode)},
      'onCheck':(event,treeId,treeNode)=>{this.handleClick(event,treeId,treeNode)}
    }
  }
  handleClick(event,treeId,treeNode){
    console.log(treeNode);
    console.log(this.refs.ztree.ztreeObj.getCheckedNodes());
  }
  handleCheck(event,treeId,treeNode){
    console.log(treeNode);
  }
  componentDidMount(){
    //you can add treeName prop to set this treeObj to the window 
    console.log(window.ztree);
    /**
     * 
     * {tree1: {}}
        tree1
        :
        {setting: {}, addNodes: ƒ, cancelSelectedNode: ƒ, destroy: ƒ, expandAll: ƒ,}
        __proto__
        :
        Object
     * /
  }
}

quick start

npm install

npm start

open http://127.0.0.1:3000 in you browser

component props

  • treeName (string) the global attribute name
  • nodes (required, object) the zTreee Nodes data
  • events (object) the zTree Nodes event(the zTree callback setting)
  • async (object) to load zTree Nodes as async(the zTree async setting)
  • check (object) the zTree check setting(the zTree check setting)
  • data (object) the zTree data setting
  • edit (object) the zTree eidt setting
  • view (object) the zTree view setting

please go jQuery zTree to get more infomations!

FAQ

1. jQuery is not defined?

Please install expose-loader,and add some config to your webpack config 😄

module: {
    loaders: [{
      test:require.resolve('jquery'),
      loader:'expose?jQuery!expose?$'
    }]
  }

LICENSE

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.