我使用datalist搜索我在输入字段中输入的值并且过滤了。我需要将所选的选项id发送到控制器功能。
<input list="browsers" type="text" id="searchtextbox" class="form-control" placeholder="Search" ng-model="searchText">
<datalist id="browsers">
<option ng-repeat="data in enroldata | filter: searchText" id="{{data.USERID}}" id="{{data.USERID}}" value="{{data.FIRSTNAME}} {{data.LASTNAME}}">{{data.FIRSTNAME}} {{data.LASTNAME}}</option>
</datalist>
<input type="button" class="btn btn-primary btn-flat" ng-click="enrol({{data.USERID}})" value="Send" />
在控制器中
$scope.enrol = function (USERID) {
debugger;
var value = $scope.USERID;
var val = $('#searchtextbox').val();
var states = $('#browsers');
var endVal = $(states).find('option[value="' + val + '"]');
//depending on your logic, if endVal is empty it means the value wasn't found in the datalist, you can take some action here
return endVal.text();
var USERID1 = $scope.searchText;
//var value = $('#searchText').val();
//alert($('#browsers [value="' + value + '"]').data('value'));
//var x = $('#searchtextbox').val();
//var z = $('#browsers');
//var val = $(z).find('option[value="' + x + '"]');
//var endval = val.attr('id');
//alert(endval);
debugger;
var dat = {
"courseid": localStorage.getItem("courseid")
, "USERID": USERID
}
}
我需要按用户名搜索并通过fucntion或id绑定传递USERID .... 我试图通过id调用它并传递函数返回undefined
答案 0 :(得分:0)
ng-repeat="data in enroldata | filter: searchText"
数据只能从ng-repeat内部访问
我想您只需点击(ng-click="enrol()"
)调用enroll(),然后从$scope.enrolData