javascript - multiple treeviews for data selection -
i have assignment needs done in specific way. have end code done, cant seem figure part out, , it's driving me mad. ui required have 2 tree views 1 on right , 1 on left. left tree view populated states, , each state have multiple children. right empty start. there 2 buttons. include, , exclude. when children left view selected, , include clicked move right tree. if user decides move them need move same place under same parent. last, not least, there can 1 of each child can't have duplicates when moving children new parents.
i can use combination of html, css, javascript, , jquery.
here have far. have tried many other things, recent.
css
#menutree li { list-style: none; /* list item li dots invisible */ } li .menu_label + input[type=checkbox] { opacity: 0; /* checkboxes invisible , use no space */ } /* display: none; better fails in ie8 */ li .menu_label { cursor: pointer; /* cursor changes when mouse on class */ } /* add many user-select: none; commands here */ li .menu_label + input[type=checkbox] + ol > li { display: none; /* prevents sublists below unchecked labels displaying */ } li .menu_label + input[type=checkbox]:checked + ol > li { display: block; /* display submenu on click */ } .selected { background-color:#efefef; } jquery
$('#move_left').click(function() { $('.list1').append($('.list2 .selected').removeclass('selected')); }); $('#move_right').click(function() { $('.list2').append($('.list1 .selected').removeclass('selected')); }); $('body').on('click', 'li', function() { $(this).toggleclass('selected'); }); html
<body> <ol id="menutree"> <li> <label class="menu_label" for="c1">menu gen14 am0a1</label> <input type="checkbox" id="c1" /> <!-- input must follow label safari --> <ol> <li> <ul class="list1"> <li class="page">page ap1a1</li> <li> page ap1a2</li> </ul> </ol> </ol> </body> <input type='button' value='<<' id='move_left'/> <input type='button' value='>>' id='move_right'/>
stupid example not take children ordering under consideration, logic presented should preserved
<div class="half"> <ol id="one"> <li id="alaska"> alaska <ul> <li data-id="alaska"><input type="checkbox"> children 1</li> <li data-id="alaska"><input type="checkbox"> children 2</li> <li data-id="alaska"><input type="checkbox"> children 3</li> </ul> </li> <li id="washington"> washington <ul> <li data-id="washington"><input type="checkbox"> children 1</li> <li data-id="washington"><input type="checkbox"> children 2</li> <li data-id="washington"><input type="checkbox"> children 3</li> </ul> </li> <li id="texas"> texas <ul> <li data-id="texas"><input type="checkbox"> children 1</li> <li data-id="texas"><input type="checkbox"> children 2</li> <li data-id="texas"><input type="checkbox"> children 3</li> </ul> </li> </ol> <button type="button" class="include">include</button> </div> <div class="half"> <ol id="two"></ol> <button type="button" class="exclude">exclude</button> </div> $(function(){ $('.include').click(function(e){ var $checks = $("input:checked"); $.each($checks, function(k,v){ var tempid = $(this).parent().data('id'); if( !$('#two').find('[data-id="'+tempid+'"]').length ){ var element = $(this).parent().detach(); $('#two').append(element); } }); }); $('.exclude').click(function(e){ var $checks = $("input:checked"); $.each($checks, function(k,v){ var tempid = $(this).parent().data('id'); var element = $(this).parent().detach(); $('#one').find('#'+tempid+' ul').append(element); }); }); });
Comments
Post a Comment