jQuery Easyui Treegrid가 표시 체크박스 기능을 구현하는 방법의 예
이 기사에서는 예제 코드를 통해 체크박스 기능을 표시하는 jQuery Easyui Treegrid 방법을 소개합니다. 코드가 간단하고 이해하기 쉽고, 매우 좋으며, 필요한 친구가 참고할 수 있습니다.
다음은 다음과 같습니다. 아래 사진의 글을 통해 소개합니다. Treegrid를 구현하는 방법은 무엇인가요?
요구 사항: 동적 로딩; 패키지 라이브러리/또는 미러를 표시하기 위한 정리 유형 판단(열이 다르며 미러 열이 4개임) 확인란을 선택하면 후속 확인란이 선택 취소됩니다. 상태.
다음은 특정 코드입니다.
1, Treegrid 초기화, (여러 유형 열이 있는데, 이는 백엔드 직원이 제공한 필드 이름이지만 여러 유형을 만들고 싶지는 않지만... 땀)
var root = 20543; //初始化产品树 function InitProductTreeGrid(rootid) { var type = '<%=Controler.ProductType%>'; var ishowPack = true; var ishowMirro = true; //1,包库;2,镜像 if (type == '1') { ishowPack = false; ishowMirro = true; } else { ishowPack = true; ishowMirro = false; }; $('#tt_Product').treegrid({ url: '../Handlers/Contract_ProductHandler.ashx', queryParams: { handlertype: "InitProductTreeGrid", ContractId: $('#ContractId').val(), CatalogId: rootid, pindex: $('#pindex').val() }, idField: 'id', width: 930, treeField: 'CatalogName', fitColumns: true, //宽度自适应窗口 rownumbers: false, //是否加行号 singleSelect: true, scrollbarSize: 0, //去除滚动条,否则右边最后一列会自动多处一块 columns: [[ { title: '产品列表', field: 'CatalogName', width: 210 }, { title: '产品ID', field: 'CatalogId', hidden: true }, { title: '父产品ID', field: 'ParentId', hidden: true }, { title: '父产品名称', field: 'ParentName', hidden: true }, { title: '产品类型', field: 'ProductType', hidden: true }, { title: '是否为子节点', field: 'isLeaf', hidden: true }, //备注:(1,是;0,否) { title: '是否为父节点', field: 'isParent', hidden: true }, { title: 'IsChecked', field: 'IsCheck', hidden: true }, { title: 'CurrentYearPrices', field: 'type1', hidden: true }, { title: 'MirrorCurrentYearPrices', field: 'type3', hidden: true }, { title: 'MirrorEarlyPrices', field: 'type4', hidden: true }, { title: 'MirrorPrevious3YearPrices', field: 'type5', hidden: true }, { field: 'CurrentYearPrices', title: '当前价格', width: 200, hidden: ishowPack, formatter: function (value, rec, index) { var d = '<input type="checkbox" name="CurrentYearPrices" catalogid="' + rec.CatalogId + '" ' + (rec.type1 == 'True' ? 'checked="checked"' : '') + ' id="CurrentYearPrices' + rec.CatalogId + '" onclick="showProductTree(this,\'CurrentYearPrices\',' + rec.CatalogId + ',' + rec.isParent + ');" parent="CurrentYearPrices' + rec.ParentId + '" isparent="' + rec.isParent + '" value="' + value + '" /> ' + (value != 0 ? value.substr(0, value.length - 2) : '0.00'); return d; } }, { field: 'MirrorCurrentYearPrices', title: '当前价格', width: 200, hidden: ishowMirro, formatter: function (value, rec, index) { var d = '<input type="checkbox" name="MirrorCurrentYearPrices" catalogid="' + rec.CatalogId + '" ' + (rec.type3 == 'True' ? 'checked="checked"' : '') + ' id="MirrorCurrentYearPrices' + rec.CatalogId + '" onclick="showProductTree(this,\'MirrorCurrentYearPrices\',' + rec.CatalogId + ',' + rec.isParent + ');" parent="MirrorCurrentYearPrices' + rec.ParentId + '" isparent="' + rec.isParent + '" value="' + value + '" /> ' + value.substr(0, value.length - 2); //var d = '<span name="CurrentYearMirrorPrice" id="CurrentYearMirrorPrice' + rec.CatalogId + '" class="tree-checkbox tree-checkbox0">' + value + '</span>'; return d; } }, { field: 'MirrorPrevious3YearPrices', title: '前阶段价格', width: 200, hidden: ishowMirro, formatter: function (value, rec, index) { var d = '<input type="checkbox" name="MirrorPrevious3YearPrices" catalogid="' + rec.CatalogId + '" ' + (rec.type5 == 'True' ? 'checked="checked"' : '') + ' id="MirrorPrevious3YearPrices' + rec.CatalogId + '" onclick="showProductTree(this,\'MirrorPrevious3YearPrices\',' + rec.CatalogId + ',' + rec.isParent + ');" parent="MirrorPrevious3YearPrices' + rec.ParentId + '" isparent="' + rec.isParent + '" value="' + value + '" /> ' + value.substr(0, value.length - 2); return d; } }, { field: 'MirrorEarlyPrices', title: '早期价格', width: 200, hidden: ishowMirro, formatter: function (value, rec, index) { var d = '<input type="checkbox" name="MirrorEarlyPrices" catalogid="' + rec.CatalogId + '" ' + (rec.type4 == 'True' ? 'checked="checked"' : '') + ' id="MirrorEarlyPrices' + rec.CatalogId + '" onclick="showProductTree(this,\'MirrorEarlyPrices\',' + rec.CatalogId + ',' + rec.isParent + ');" parent="MirrorEarlyPrices' + rec.ParentId + '" isparent="' + rec.isParent + '" value="' + value + '" /> ' + value.substr(0, value.length - 2); return d; } }, { field: 'type0', title: '是否赠送', width: 200, formatter: function (value, rec, index) { //alert(rec.isPresent); var d = '<input type="checkbox" name="IsPresent" catalogid="' + rec.CatalogId + '" ' + (rec.type0 == 'True' ? 'checked="checked"' : '') + ' id="IsPresent' + rec.CatalogId + '" onclick="showProductTree(this,\'IsPresent\',' + rec.CatalogId + ',' + rec.isParent + ');" parent="IsPresent' + rec.ParentId + '" isparent="' + rec.isParent + '" value="0" /> '; return d; } } ]], loadFilter: function (data, parentId) { //逐层加载 function setData() { var todo = []; for (var i = 0; i < data.length; i++) { todo.push(data[i]); } while (todo.length) { var node = todo.shift(); if (node.children) { node.state = 'closed'; node.children1 = node.children; node.children = undefined; todo = todo.concat(node.children1); } } } setData(data); var tg = $(this); var opts = tg.treegrid('options'); opts.onBeforeExpand = function (row) { if (row.children1) { tg.treegrid('append', { parent: row[opts.idField], data: row.children1 }); row.children1 = undefined; tg.treegrid('expand', row[opts.idField]); } return row.children1 == undefined; }; return data; }, onLoadSuccess: function (row, data) { //alert(data[0].CatalogId) RelativeTreeGridCheck(); } }); };
2. onLoadSuccess
var parentcid; var ispid; var tempid; //父节点选中关联子节点选中 function RelativeTreeGridCheck() { var rows = $('#addProductTbl').find('.datagrid-view2 .datagrid-body .datagrid-btable tr'); for (var i = 0; i < rows.length; i++) { if ($(rows).eq(i).attr('node-id') != undefined) { parentcid = ""; ispid = -1; tempid = ""; catalogid = $(rows).eq(i).attr('node-id'); //alert(catalogid); var cols = $(rows).eq(i).find('td'); var fields = ''; for (var j = 0; j < cols.length; j++) { fields = $(cols).eq(j).attr('field'); //alert('fields:' + fields); switch (fields) { case 'CurrentYearPrices': case 'MirrorCurrentYearPrices': case 'MirrorPrevious3YearPrices': case 'MirrorEarlyPrices': case 'type0': if ($(cols).eq(j).find('p input:checked').length > 0) { parentcid = $(cols).eq(j).parent().find("td[field='CatalogId']").find('p').html(); ispid = $(cols).eq(j).parent().find("td[field='isParent']").find('p').html(); contractproducttype = $(cols).eq(j).find('p input').attr('name'); if (ispid == '1') { //获取checkbox对象 var obj = $(cols).eq(j).find('p input:checkbox'); //如果父节点选中,自己点也连带选中 showProductTree(obj, contractproducttype, parentcid, ispid) } } break; } } } } } function showProductTree(obj, catalogtype, id, isparent) { //alert(id.indexof('2')); if (isparent == 1) { //当前节点下包库子节点 //alert('$(obj).attr(checked)' + $(obj).attr('checked')); var state = $(obj).attr('checked') == undefined ? false : true; //alert('state:'+state+' id:'+id); //找出子节点 var nodes = $('input[name="' + catalogtype + '"][parent="' + catalogtype + id + '"]'); nodes.each(function () { //alert('$(this).attr(checked):' + $(this).attr('checked')); var curobjstate = $(this).attr('checked') == undefined ? false : true; disabledOthersCatalogType($(this), state, catalogtype) //alert('curobjstate:' + curobjstate + ' state:' + state + ' id:' + id + ' isparent: ' + $(this).attr('isparent')); if (curobjstate == state && $(this).attr('isparent') == '0') { //alert('leaf'); //如果当前节点的选中状态和父节点不同,并且当前节点不是父节点 $(this).attr('checked', state); $(this).prop('checked', state); } else { //alert('$(this).attr(catalogid)' + $(this).attr('catalogid') + '---$(this).attr(isparent)' + $(this).attr('isparent')); $(this).attr('checked', state); $(this).prop('checked', state); showProductTree($(this), catalogtype, $(this).attr('catalogid'), $(this).attr('isparent')) } if (state) { $(this).removeAttr('disabled'); } }); $(obj).prop('checked', state); disabledOthersCatalogType($(obj), state, catalogtype) } else { var state = $(obj).attr('checked') == undefined ? false : true; //alert(state); //alert(catalogtype); disabledOthersCatalogType($(obj), state, catalogtype) updateParentNodeCheckState($(obj), state, catalogtype) } } //修改其他产品类型的checkbox的只读状态 function disabledOthersCatalogType(obj, state, catalogtype) { $('input[catalogid="' + $(obj).attr('catalogid') + '"]').each(function () { if ($(this).attr('name') != catalogtype) { if (state) { $(this).attr('disabled', 'disabled'); } else { $(this).removeAttr('disabled'); } $(this).attr('checked', false).prop('checked', false); } }); } //查找上一层节点,修改其状态 function updateParentNodeCheckState(obj, state, catalogtype) { var pid = $(obj).attr('parent'); //如果父节点是根节点,则不再执行 if (pid == catalogtype + root || $('#' + pid).length == 0) return; var parent = $('#' + pid); if (!state) { //取消父节点的选中状态 parent.attr('checked', false) parent.prop('checked', false) } else { //alert('pid:'+pid+'---'+$('input[parent="' + pid + '"]:checked').length+'------'+$('input[parent="' + pid + '"]').length); //alert('checkedLen:' + $('input[parent="' + pid + '"]:checked').length + ' len:' + $('input[parent="' + pid + '"]').length); //子节点全部选中 if ($('input[parent="' + pid + '"]:checked').length == $('input[parent="' + pid + '"]').length) { parent.attr('checked', true); parent.prop('checked', true); } } //修改其他产品类型的checkbox的只读状态 disabledOthersCatalogType(parent, state, catalogtype) //继续查找上一层节点 updateParentNodeCheckState(parent, state, catalogtype) }
3의 RelativeTreeGridCheck() 계단식 메소드는 상대적으로 접합이 복잡하므로 매개변수 전달 코드에 대해 이야기하겠습니다
//新增产品单击操作处理 function subAddProduct() { 5 var strJson = ''; var selectedvalued = $('#cbo_selFirstCombbox').combobox('getValue'); //下拉框选中的value selectedvalued = selectedvalued == '' ? '20544' : selectedvalued; // var ids = ''; var rows = $('#addProductTbl').find('.datagrid-view2 .datagrid-body .datagrid-btable tr'); strJson += "["; for (var i = 0; i < rows.length; i++) { catalogid = -1; catalogname = ''; productfather = -1; contractproducttype = ''; quoteprice = -1; isfather = -1; productfathername = ''; if ($(rows).eq(i).attr('node-id') != undefined) { catalogid = $(rows).eq(i).attr('node-id'); //alert(catalogid); var cols = $(rows).eq(i).find('td'); var fields = ''; for (var j = 0; j < cols.length; j++) { fields = $(cols).eq(j).attr('field'); //alert('fields:' + fields); switch (fields) { case 'CatalogName': $(cols).eq(j).find('p span').each(function (index) { if ($(cols).eq(j).find('p span').eq(index).hasClass('tree-title')) { catalogname = $(cols).eq(j).find('p span').eq(index).html(); } }); //alert(catalogname); break; case 'ParentId': productfather = $(cols).eq(j).find('p').html(); break; case 'IsCheck': //原树选中节点id的获取(不包含修改的id节点),此步骤目的是为了配合后台方法,作用是先删除当前版本下所有树选中的节点,再获取页面中修改后的 //节点,进行更新操作 var oldcheck = $(cols).eq(j).find('p').html(); if (oldcheck == 'True') { var cid = $(cols).eq(j).parent().find("td[field='CatalogId']").find('p').html(); ids += cid + ','; //alert(ids) } break; case 'CurrentYearPrices': case 'MirrorCurrentYearPrices': case 'MirrorPrevious3YearPrices': case 'MirrorEarlyPrices': case 'type0': if ($(cols).eq(j).find('p input:checked').length > 0) { isfather = $(cols).eq(j).parent().find("td[field='isParent']").find('p').html(); productfathername = $(cols).eq(j).parent().find("td[field='ParentName']").find('p').html(); contractproducttype = $(cols).eq(j).find('p input').attr('name'); if (contractproducttype == 'IsPresent') { var type = '<%=Controler.ProductType%>'; contractproducttype = type == '1' ? 'CurrentYearPrices' : 'MirrorCurrentYearPrices'; //如果类型为镜像,则默认为镜像当年 //alert($(cols).eq(j).parent().find("td[field='" + contractproducttype + "']").find('p input').val()); //quoteprice = 0; quoteprice = $(cols).eq(j).parent().find("td[field='" + contractproducttype + "']").find('p input').val(); ispresent = 1; } else { quoteprice = $(cols).eq(j).find('p input').val(); ispresent = 0; } //alert('name:' + $(cols).eq(j).find('p input').attr('name') + ' value:' + $(cols).eq(j).find('p input').val()); } break; } } //alert('catalogid:' + catalogid + '--catalogname:' + catalogname + '--productfather:' + productfather + '--contractproducttype:' + contractproducttype + '--quoteprice:' + quoteprice); if (catalogid != -1 && catalogname != '' && productfather != -1 && contractproducttype != '' && quoteprice != -1 && productfathername != '') { strJson += "{\"ProductID\":\"" + catalogid + "\",\"ContractProductType\":\"" + contractproducttype + "\",\"ProductFather\":\"" + productfather + "\",\"Productname\":\"" + catalogname + "\",\"Quotedprice\":\"" + quoteprice + "\",\"Oldproduct\":\"" + oldproduct + "\",\"IsPresent\":\"" + ispresent + "\",\"ContractID\":\"" + $('#ContractId').val() + "\",\"SelectedID\":\"" + selectedvalued + "\",\"IsParent\":\"" + isfather + "\",\"ProductFatherName\":\"" + productfathername + "\",\"IsNull\":\"0\"},"; } } } //alert(strJson); if (strJson == '[') { strJson = "[{\"ContractID\":\"" + $('#ContractId').val() + "\",\"SelectedID\":\"" + selectedvalued + "\",\"IsNull\":\"1\"}]"; } else { strJson = strJson.substr(0, strJson.length - 1); strJson += "]"; } ids = ids.substr(0, ids.length - 1); subProduct(strJson, ids); //alert(rows.length); } //新增产品提交操作 function subProduct(strJson, ids) { $.post('../Handlers/Contract_ProductHandler.ashx', { 'handlertype': 'subAddProduct', 'strJson': strJson, 'ids': ids, 'pindex': $('#pindex').val() }, function (responseData) {121 switch (responseData.Status) { case "success": //成功的操作 $.messager.alert('提示', responseData.Msg); $('#ProductWinTree').window('close'); //$('#selFirstCombbox').val('6774'); $('#dg_Product').datagrid('reload'); break; case "failed": //失败的操作 $.messager.alert('提示', responseData.Msg); break; } }, 'json'); }
Sum 메리
위 내용은 jQuery Easyui Treegrid가 표시 체크박스 기능을 구현하는 방법의 예의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











jQuery 참조 방법에 대한 자세한 설명: 빠른 시작 가이드 jQuery는 웹 사이트 개발에 널리 사용되는 JavaScript 라이브러리로, JavaScript 프로그래밍을 단순화하고 개발자에게 풍부한 기능을 제공합니다. 이 기사에서는 jQuery의 참조 방법을 자세히 소개하고 독자가 빠르게 시작할 수 있도록 구체적인 코드 예제를 제공합니다. jQuery 소개 먼저 HTML 파일에 jQuery 라이브러리를 도입해야 합니다. CDN 링크를 통해 소개하거나 다운로드할 수 있습니다.

jQuery에서 PUT 요청 방법을 사용하는 방법은 무엇입니까? jQuery에서 PUT 요청을 보내는 방법은 다른 유형의 요청을 보내는 것과 유사하지만 몇 가지 세부 사항과 매개 변수 설정에 주의해야 합니다. PUT 요청은 일반적으로 데이터베이스의 데이터 업데이트 또는 서버의 파일 업데이트와 같은 리소스를 업데이트하는 데 사용됩니다. 다음은 jQuery에서 PUT 요청 메소드를 사용하는 구체적인 코드 예제입니다. 먼저 jQuery 라이브러리 파일을 포함했는지 확인한 다음 $.ajax({u를 통해 PUT 요청을 보낼 수 있습니다.

jQuery는 프런트엔드 개발에 널리 사용되는 빠르고, 작고, 기능이 풍부한 JavaScript 라이브러리입니다. 2006년 출시 이후 jQuery는 많은 개발자가 선택하는 도구 중 하나가 되었지만 실제 애플리케이션에서는 몇 가지 장점과 단점도 있습니다. 이 기사에서는 jQuery의 장점과 단점을 심층적으로 분석하고 구체적인 코드 예제를 통해 설명합니다. 장점: 1. 간결한 구문 jQuery의 구문 디자인은 간결하고 명확하여 코드의 가독성과 쓰기 효율성을 크게 향상시킬 수 있습니다. 예를 들어,

jQuery를 사용하여 요소의 높이 속성을 제거하는 방법은 무엇입니까? 프런트엔드 개발에서는 요소의 높이 속성을 조작해야 하는 경우가 종종 있습니다. 때로는 요소의 높이를 동적으로 변경해야 할 수도 있고 요소의 높이 속성을 제거해야 하는 경우도 있습니다. 이 기사에서는 jQuery를 사용하여 요소의 높이 속성을 제거하는 방법을 소개하고 구체적인 코드 예제를 제공합니다. jQuery를 사용하여 높이 속성을 연산하기 전에 먼저 CSS의 높이 속성을 이해해야 합니다. height 속성은 요소의 높이를 설정하는 데 사용됩니다.

제목: jQuery 팁: 페이지에 있는 모든 태그의 텍스트를 빠르게 수정하세요. 웹 개발에서는 페이지의 요소를 수정하고 조작해야 하는 경우가 많습니다. jQuery를 사용할 때 페이지에 있는 모든 태그의 텍스트 내용을 한 번에 수정해야 하는 경우가 있는데, 이는 시간과 에너지를 절약할 수 있습니다. 다음은 jQuery를 사용하여 페이지의 모든 태그 텍스트를 빠르게 수정하는 방법을 소개하고 구체적인 코드 예제를 제공합니다. 먼저 jQuery 라이브러리 파일을 도입하고 다음 코드가 페이지에 도입되었는지 확인해야 합니다. <

제목: jQuery를 사용하여 모든 태그의 텍스트 내용을 수정합니다. jQuery는 DOM 작업을 처리하는 데 널리 사용되는 인기 있는 JavaScript 라이브러리입니다. 웹 개발을 하다 보면 페이지에 있는 링크 태그(태그)의 텍스트 내용을 수정해야 하는 경우가 종종 있습니다. 이 기사에서는 jQuery를 사용하여 이 목표를 달성하는 방법을 설명하고 구체적인 코드 예제를 제공합니다. 먼저 페이지에 jQuery 라이브러리를 도입해야 합니다. HTML 파일에 다음 코드를 추가합니다.

jQuery 요소에 특정 속성이 있는지 어떻게 알 수 있나요? jQuery를 사용하여 DOM 요소를 조작할 때 요소에 특정 속성이 있는지 확인해야 하는 상황이 자주 발생합니다. 이 경우 jQuery에서 제공하는 메소드를 사용하여 이 기능을 쉽게 구현할 수 있습니다. 다음은 jQuery 요소에 특정 속성이 있는지 확인하기 위해 일반적으로 사용되는 두 가지 방법을 특정 코드 예제와 함께 소개합니다. 방법 1: attr() 메서드와 typeof 연산자를 // 사용하여 요소에 특정 속성이 있는지 확인

jQuery는 웹 페이지에서 DOM 조작 및 이벤트 처리를 처리하는 데 널리 사용되는 인기 있는 JavaScript 라이브러리입니다. jQuery에서 eq() 메서드는 지정된 인덱스 위치에서 요소를 선택하는 데 사용됩니다. 구체적인 사용 및 적용 시나리오는 다음과 같습니다. jQuery에서 eq() 메서드는 지정된 인덱스 위치에 있는 요소를 선택합니다. 인덱스 위치는 0부터 계산되기 시작합니다. 즉, 첫 번째 요소의 인덱스는 0이고 두 번째 요소의 인덱스는 1입니다. eq() 메소드의 구문은 다음과 같습니다: $("s
