Giter Site home page Giter Site logo

mtrsearchztree's Introduction

zTreeSelectM

项目介绍

项目中需要用到下拉树多选功能,找到两个相关组件moretop-layui-select-ext和wujiawei0926-treeselect,但是moretop-layui-select-ext不支持树结构,wujiawei0926-treeselect不支持多选,于是干脆仿照moretop-layui-select-ext动手写了一个组件,选择zTree而没有选择layuiTree的主要原因是layuiTree暂不支持父子关系取消。

渲染代码

var _zTreeSelectM = zTreeSelectM({
    elem: '#zTreeSelectM',//元素容器【必填】          
    data: './json/1.json',//候选数据【必填】
    width: 600,  //设置了长度    
    selected: [3,6,29],//默认值            
    max: 3,//最多选中个数,默认5            
    name: 'field',//input的name 不设置与选择器相同(去#.)
    delimiter: ',',//值的分隔符           
    field: { idName: 'id', titleName: 'name' },//候选项数据的键名 
    zTreeSetting: { //zTree设置
        check: {
            enable: true,
            chkboxType: { "Y": "", "N": "" }
        },
        data: {
            simpleData: {
                enable: false
            },
            key: {
                name: 'name',
                children: 'children'
            }
        }
    }
});	

获取选中数据代码

form.on('submit(demo)',function(data){			 
	console.log('zTreeSelectM 当前选中的值名:',_zTreeSelectM.selected);
	console.log('zTreeSelectM 当前选中的值:',_zTreeSelectM.values);
	console.log('zTreeSelectM 当前选中的名:',_zTreeSelectM.names);      
  
  	var formData = data.field;
  	console.log('表单对象:',formData);
  	return false;
})
	
//监听重置按钮
$('form').find(':reset').click(function(){
	$('form')[0].reset();
	_zTreeSelectM.set();//默认值
	return false;
});

$("#set").on('click',function(e){			 
	_zTreeSelectM.set([4,7,13]);
	return false;
})

效果图

效果

码云演示

码云演示

mtrsearchztree's People

Watchers

James Cloos avatar Cindy avatar

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.