0
我想创建一个角度的月份的天数的下拉列表,所选的数字将被传递到elasticsearch查询中。
问题是,为了有一个'全天'选项查询要求所有输入为'*'。
代码工作,如果我也像这样的*显示的所有选项,但显然这不是对用户来说非常可读:角度选择选项不能正常工作
JS
$scope.daysInMonthArray = ['*']
$scope.day = $scope.daysInMonthArray[0];
$scope.daysInMonth = function (month, year) {
return 32 - new Date(year, month, 32).getDate()
};
for (var i=0; i < $scope.daysInMonth(n, $scope.year); i++) {
$scope.daysInMonthArray.push(i + 1)
}
HTML
<select
class="form-control"
ng-model="day"
ng-options="day for day in daysInMonthArray">
</select>
而且我有试图用下面的方法让它显示'all'这个单词,但它不起作用。它回发给查询的只是'[object object]'。
JS
$scope.daysInMonthArray = [{'name': 'all', 'value': '*'}]
$scope.day = $scope.daysInMonthArray[0];
$scope.daysInMonth = function (month, year) {
return 32 - new Date(year, month, 32).getDate()
};
for (var i=0; i < $scope.daysInMonth(n, $scope.year); i++) {
$scope.daysInMonthArray.push({'name': i + 1, 'value': i + 1})
}
HTML
<select
class="form-control"
ng-model="day"
ng-options="day as day.name for day in daysInMonthArray track by day.value">
</select>
我写的第二个错误还是有要去这个更好的办法?
尝试使用该选项的索引,如果选择所有的传球被索引,然后解雇你的查询是指数。您也可以通过使用下拉列表的值来完成。 –
您如何使用该值来查询elasticsearch。你应该只需要使用'day.value' –
在发布我的答案之前,我没有看到你的第二个实现。看上去不错。我正在删除我的答案。 –