Home > Web Front-end > JS Tutorial > body text

Ztree obtains the checked node data and merges it with the form information

不言
Release: 2018-07-09 15:42:19
Original
1908 people have browsed it

This article mainly introduces how ztree obtains the checked node data and merges it with the form information. It has a certain reference value. Now I share it with you. Friends in need can refer to it.

Get the form data separately and ztree data are simple, but how to merge them into a reasonable json data?

Solution:

$('#save').click(function () {
        var nodes = zTree.getCheckedNodes(true);   //获取被勾选/未勾选的节点集合
        // console.log(nodes);
        var id;    //存放节点id
        var nodestring="";   //拼接节点的id为一个字符串      
        var Sendjson={};
        var resultjson;
        for(var i=0;i<nodes.length;i++) {
            id=nodes[i].id;
            idarry[i]=id;
            if(i<nodes.length-1) {
                nodestring += id + ',';
            }
            else
                nodestring+=id;
        }
        Sendjson.data=nodestring;
        var form = $('#Addmessge').serializeJSON();//表单信息
        resultjson=Object.assign(Sendjson,form)    //合并两个对象
        console.log(JSON.stringify(resultjson));

    });
Copy after login

The specific idea is to first get the checked node, then get the corresponding id value, and spell the id value into a string, and then combine the form information and the spliced ​​characters Strings are merged through
Object.assign(Sendjson, form)

Result

data为节点id,即已经勾选的id值,后面为一个表单的信息
{"data":"1,11,111,1111,1112","Cname":"","Cencoding":"","Sequence":"","Ucategory":"test1","Rdetial":"test1","Ninformation":""}
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone's learning. For more related content, please Follow PHP Chinese website!

Related recommendations:

Learning about the selector of jQuery source code

The interface object of EventListener in addEventListener

The above is the detailed content of Ztree obtains the checked node data and merges it with the form information. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template