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' –
在發佈我的答案之前,我沒有看到你的第二個實現。看上去不錯。我正在刪除我的答案。 –