如何使用 ng-repeat 和过滤器获取数据列表选择的选项 ids 值?
How to get datalist selected options id's value with ng-repeat and fillter?
我使用数据列表搜索我在输入字段中输入的值,filtered.i 需要将所选选项 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
}
}
我需要按用户名搜索并通过函数或 ID 绑定传递 USERID....
我试图通过 id 调用它并通过函数传递它的 return undefined
ng-repeat="data in enroldata | filter: searchText"
数据只能从 ng-repeat 内部访问
我认为您可以简单地在单击 (ng-click="enrol()"
) 时调用 enrol() 并从 $scope.enrolData
获取控制器内部的数据
我使用数据列表搜索我在输入字段中输入的值,filtered.i 需要将所选选项 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
}
}
我需要按用户名搜索并通过函数或 ID 绑定传递 USERID.... 我试图通过 id 调用它并通过函数传递它的 return undefined
ng-repeat="data in enroldata | filter: searchText"
数据只能从 ng-repeat 内部访问
我认为您可以简单地在单击 (ng-click="enrol()"
) 时调用 enrol() 并从 $scope.enrolData