Angularjs过滤搜索文本

时间:2017-03-14 18:51:49

标签: angularjs

我想要使用angularjs过滤器。如何在设施中找到阿门。 amen = 1; 设施=" 1,3,7,9,12和#34 ;;

这是我的代码:



<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script>
<input type="checkbox" name="more_filter[]" value="1" class="pull-left amenities" id="amen-1" ng-checked="false">


amenities = "1, 3, 7, 9, 12";

//amen 1
$( "#amen-1" ).on( "click", function() {
var amen = document.getElementById("amen-1").val();
$scope.amen = amen;
$scope.$apply();
$scope.ot_Filter = function (location) {
    return location.amenities == $scope.amen;
};
});

   
&#13;
&#13;
&#13;

我想在设施中搜索阿门。如何在此行上进行更改:

&#13;
&#13;
location.amenities == $scope.amen
&#13;
&#13;
&#13;

谢谢..

编辑: @ Gonzalo的帮助解决了问题:

&#13;
&#13;
<input type="checkbox" name="more_filter[]" value="1" class="pull-left amenities" ng-click="am_1();" id="map-search-amenities-1">
&#13;
&#13;
&#13;

$scope.am_1 = function()
{
var kontrol = document.getElementById("map-search-amenities-1").checked;
if (kontrol==true) {
$scope.ot_Filter = function (location) {
return location.amenities.indexOf(1)==0;
};
} else {
$scope.ot_Filter = function (location) {
return location.amenities;
};
}
}

1 个答案:

答案 0 :(得分:0)

使用内置函数的indexOf() javascript来搜索字符串。

location.amenities.indexOf(<yoursearch>);

另一个提示:

您应该使用ng-click而不是on('click')。您可以删除scope.$apply()