jquery - How to correctly select default option in list? -
i have 6 lists whiich populate via script. im using angular js , html looks this:
<div class="advancedsearch hidden"> <div class="col-md-4 col-xs-12"> <select name="number" ng-model="numbers" ng-change="listsearchchnage(numbers, 'number')" class="form-control" > <option value="">choose nummer</option> <option ng:repeat="number in numbers" value="{{number}}">{{number}}</option> <!-- select month --> </select> </div> <div class="col-md-4 col-xs-12"> <select name="objdesc" class="form-control" ng-model="objektdescriptions" ng-change="listsearchchnage(objektdescriptions,'objektdescription')"> <option value="">choose something</option> <option ng:repeat="desc in objektdescriptions" value="{{desc}}">{{desc}}</option> <!-- select month --> </select> </div> <div class="col-md-4 col-xs-12"> <select name="tenantname" class="form-control" ng-model="customernames" ng-change="listsearchchnage(customernames,'customername')" > <option value="">choose somethingelse</option> <option ng:repeat="customername in customernames" value="{{customername}}">{{customername}}</option> </select> </div> <div class="col-md-4 col-xs-12"> <select name="datesearch" class="form-control" ng-model="registerdates" ng-change="listsearchchnage(registerdates,'registerdate')" > <option value="">choose somethingelse</option> <option ng:repeat="date in registerdates" value="{{date}}">{{date}}</option> <!-- select month --> </select> </div> <div class="col-md-4 col-xs-12"> <select name="managersearch" class="form-control" ng-model="managers" ng-change="listsearchchnage(managers,'manager')"> <option value="">choose somethingelse</option> <option ng:repeat="manager in managers" value="{{status}}">{{manager}}</option> <!-- select month --> </select> </div> <div class="col-md-4 col-xs-12"> <select name="advstatussearch" class="form-control" ng-model="advstatuses" ng-change="listsearchchnage(advstatuses,'s')"> <option value="">choose status</option> <option ng:repeat="s in advstatuses" value="{{s}}">{{s}}</option> <!-- select month --> </select> </div>
script:
$.each(data, function(i, v) { $scope.numbers.push(v.orderraderid); if ($.inarray($.trim(v.orderraderid), $scope.numbers) == -1) $scope.numbers.push(v.orderraderid); if ($.inarray($.trim(v.objektbeteckning), $scope.objektdescriptions) == -1) $scope.objektdescriptions.push(v.objektbeteckning); if ($.inarray(v.kundnamn, $scope.customernames) == -1) $scope.customernames.push(v.kundnamn); if ($.inarray(v.anmdatum, $scope.registerdates) == -1) $scope.registerdates.push(v.anmdatum); if ($.inarray($.trim(v.status), $scope.advstatuses) == -1) $scope.advstatuses.push(v.status); if ($.inarray($.trim(v.utforare), $scope.managers) == -1) $scope.managers.push(v.utforare); });
all lists except last 1 renders "status" first option selected default.
ive tried hardcoding the select attribute "selected=selected" did not work. ive tried setting via script so:
$(".advancedsearch select option").each(function () { $(this).removeattr('selected'); });
but nothing works. doing wrong?
took me while changed
<option ng:repeat="status in advstatuses" value="{{status}}">{{status}}</option>
to
<option ng:repeat="status in advstatuses" value="">{{status}}</option>
and solved problem. don't understand why happened , appreciate explenation if has one?
Comments
Post a Comment