我可以从输入框更改AngularJS的dirpagination过滤器以选择框吗?

时间:2016-11-02 06:36:21

标签: javascript html angularjs

我一直在搞乱AngularJS的dirpagination库,请参考链接: https://github.com/michaelbromley/angularUtils/tree/master/src/directives/pagination

请参阅代码演示: http://plnkr.co/edit/Wtkv71LIqUR4OhzhgpqL?p=preview

我想知道,我可以将输入框更改为选择框并获得相同的功能。例如。我正在过滤一些名称,但名称只能从选择框中选择,内容将根据选择框的输入进行过滤。

我试图通过以下方式实现这一目标:

function callFilter(Name) {
        document.getElementById("search").value = Name;
}
<span style="float:right;">
        <select style="height: 30px;" onchange="callFilter(this.value);">
    		<option value="All_Names" selected>Names</option>
    	</select>
    	<input ng-model="q" id="search" class="form-control" value="" type="hidden">
    	<input value="10" class="form-control" ng-model="pageSize" type="hidden">
</span>

通过这样做,我设法操纵隐藏的输入框,但是,输入框中更改的值将不会采取实际操作来提交我的内容。 我该怎么办?提前谢谢!

2 个答案:

答案 0 :(得分:1)

检查下拉代码和demo here

<select ng-model="q" class="form-control">
     <option value='' Selected>Select</option>
     <option value="meal 1">Meal 1</option>
     <option value="meal 2">Meal 2</option>
     <option value="meal 3">Meal 3</option>
</select>

答案 1 :(得分:0)

试试这个

&#13;
&#13;
$scope.getFilter = function() {
    var filter = {};
    filter[$scope.filter] = $scope.query;
    return filter;
};
&#13;
<select ng-model="filter">
    <option value='firstname'>by firstname </option>
    <option value='lastname'>by lastname </option>
</select>

<input ng-model='query'>

<ul>
    <li ng-repeat='person in persons | filter: getFilter()'> firstname: {{person.firstname}}, lastname: {{person.lastname}}
</ul>
&#13;
&#13;
&#13;

让我知道,这篇文章是否有用......