Easyui--treegrid-Cascade selected micro-improvements to resolve the issue of unchecked.

Source: Internet
Author: User

Most of the code references network resources, but improvements have been made to the various issues that have been unchecked in network resources.

if ($.fn.treegrid) {$.extend ($.fn.treegrid.methods, {/** * cascading select * @param {Object} target * @param {Object} param * param includes two parameters: * ID: TICK the Node ID * deepcascade : Whether depth cascade * @return {TypeName} */cascadecheck:function (target, param) {var opts = $ . Data (Target[0], "Treegrid"). Options; if (opts.singleselect) return; var IDfield = opts.idfield;//Here IDfield is actually the ID parameter of the method in the API var status = false;//used to mark the status of the current node, true: Tick, false: Unchecked var selectnodes = $ (target). Treegrid (' getselections ');//Gets the current selection for (var i = 0; i < selectnodes. Length i++) {if (Selectnodes[i][idfield] = = param.id) status = TRUE; } selectchildren (Target[0], param.id, IDfield, Param.deepcascade, status); Cascade Select Parent Node selectparent (target[0], param.id, IDfield, status); /** * Cascade Select Parent Node * @param {object} target * @param {object} ID Node ID * @pa Ram {Object} status node state, true: tick, false: Unchecked * @return {TypeName} */function SELECTPA rent (target, id, IDfield, status) {var parent = $ (target). Treegrid (' getParent ', id); if (parent) {var parentid = Parent[idfield]; if (status) {$ (target). Treegrid (' select ', ParentID); } else {var haschildselected = false; var selected_hash = {}; var selectnodes = $ (target). Treegrid (' getselections ');//Gets the current selection For (var i = 0; i < selectnodes.length; i++) {Selected_hash[selectnodes[i][idfield]] = True } var children = $ (target). Treegrid (' GetChildren ', parentid); for (var i = 0; i < children.length; i++) {var childid = Children[i][idfield]; if (Selected_hash[childid]) haschildselected = true; }//Sibling does not have the selected item if (!haschildselected) $ (target). Treegrid (' unselect ', parentid ); } selectparent (Target, ParentID, IDfield, status); }}/** * Cascade Select child node * @param {object} target * @param {object} ID Node ID * @param {object} Deepcascade is a depth cascade * @param {Object} status node state, true: tick, false: Unchecked * @return {TypeName} */function Selectchildren (target, id, IDfield, Deepcascade, Statu s) {//depth Cascade first expand node if (!status && deepcascade) $ (target). Treegri D (' expand ', id); Get downlevel child nodes by ID var children = $ (target). Treegrid (' GetChildren ', id); for (var i = 0; i < children.length; i++) {var childid = Children[i][idfield]; if (status) $ (target). Treegrid (' select ', childID); else $ (target). Treegrid (' unselect ', CHildid); Selectchildren (target, childID, IDfield, Deepcascade, status);//Recursive Select Child Node}}});


The Cascadecheck method was added for Treegrid, whose parameters are ID, Deepcascade (bool).

Easyui--treegrid-Cascade selected micro-improvements to resolve the issue of unchecked.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.