javascript - Not getting id in from the selected values in multi-select list box Angular JS -
i have 2 list boxes , have move items 1 list box another. able achieve part. want take list of items in second list box id , save in database. not getting ids in second list box. best way items in list box , send controller? code:
html:
<div class="control-group"> <div class="selector"> <select multiple="multiple" id="selectleft" ng-model="taxid" ng-options="tax.taxid tax.taxname tax in taxes"></select> </div> <input id="moveright" type="button" value=" >> " ng-click="movetaxes()" /> <input id="moveleft" type="button" value=" << " ng-click="movetaxes()" /> <div class="selector"> <select id="selectright" ng-model="selectright" multiple="multiple"> </select> </div> </div> js code below:
$("#moveright,#moveleft").click(function (event) { var id = $(event.target).attr("id"); var selectfrom = id == "moveright" ? "#selectleft" : "#selectright"; var moveto = id == "moveright" ? "#selectright" : "#selectleft"; var selecteditems = $(selectfrom + " :selected").toarray(); $(moveto).append(selecteditems); selecteditems.remove; });
firstly, dont recommend using jquery in angular. secondly, thinking in jquery when "send controller".
now coming question -
define ng-options in second div.
<div class="control-group"> <div class="selector"> <select multiple="multiple" id="selectleft" ng-model="taxid" ng-options="tax.taxid tax.taxname tax in taxes"></select> </div> <input id="moveright" type="button" value=" >> " ng-click="moveright()" /> <input id="moveleft" type="button" value=" << " ng-click="moveleft()" /> <div class="selector"> <select id="selectright" ng-model="selectright" ng-options="tax.taxid tax.taxname tax in taxessecond"> </select> </div> now push element in second array taxessecond whenever move left right , remove element first array using splice , vice versa.
$scope.moveright = function(){ $scope.taxessecond.push($scope.selectedleft); $scope.taxes.splice($scope.taxes.indexof($scope.selectedleft),1); } hope can write moveleft on own.
Comments
Post a Comment