第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Angular JS 上預(yù)填充關(guān)鍵字搜索過濾器

在 Angular JS 上預(yù)填充關(guān)鍵字搜索過濾器

手掌心 2021-11-12 16:32:36
我正在嘗試在輸入字段中加載帶有預(yù)填充值的頁面。頁面和值確實會加載,盡管在我在鍵盤上輸入內(nèi)容之前它不會觸發(fā)過濾結(jié)果中的任何內(nèi)容。有沒有解決的辦法?我希望它在頁面加載后只加載過濾后的結(jié)果。我是 Angular JS 的新手,但感謝任何形式的幫助或朝著正確的方向努力。我試過了:ng-init="search.keywords='initial'" 在輸入標(biāo)簽上,這似乎不會導(dǎo)致任何過濾發(fā)生。$scope.search = { keywords: 'initial' }; 還會加載初始值,但不會觸發(fā)任何過濾。<input type="text" id="search-keywords" ng-model="search.keywords"       class="form-control" placeholder="Keyword search">$scope.$watch("search", function (newVal, oldVal) {    if (newVal) {        $scope.doFilter(newVal);    }}, true);$scope.doFilter = function (search) {    $scope.filtering = true;    $scope.filteredCourses = $scope.filterExactMatchExceptNull($scope.courses, "inst", search.inst);    $scope.filteredCourses = $scope.filterExactMatchExceptNull($scope.filteredCourses, "fos", search.fos);    $scope.filteredCourses = $scope.filterCutoff($scope.filteredCourses, search.min, search.max);    $scope.filteredCourses = $filter("filter")($scope.filteredCourses, {        code: search.code,        name: search.name,        poa: search.poa    });    $scope.filteredCourses = $scope.filterByKeywords($scope.filteredCourses, search.keywords);    $scope.limit = 15;    if ($scope.limit >= $scope.filteredCourses.length) {        $scope.limit = $scope.filteredCourses.length;    }    $scope.filtering = false;};$scope.filterByKeywords = function (courses, keywords) {    if (!keywords || keywords == "") {         return courses.filter(function (course) {            return true;        });    }     var keywordArr = keywords.toLowerCase().trim().replace(/\W+/g, " ").replace(/\s\s+/g, " ").split(",");         return courses.filter(function (course) {             var matched = false;             for (var i = 0, length = keywordArr.length; i < length; i++) {                    if (course.keywords && course.keywords.indexOf(keywordArr[i]) > -1) {                        matched = true;                        break;                    }                }                return matched;            });        };任何幫助將不勝感激!
查看完整描述

2 回答

?
縹緲止盈

TA貢獻2041條經(jīng)驗 獲得超4個贊

$watch 函數(shù)用于檢測輸入字段在加載到 DOM 后的任何變化。


所以,第一次使用它,你可以這樣做:


在元素上使用 ng-init 以在 DOM 加載時觸發(fā)過濾器方法。


ng-init="doFilter(search)"

或者


在實際監(jiān)視開始之前,在控制器級別本身調(diào)用過濾器函數(shù)一次。


$scope.search = { keywords: 'initial' }; 

$svope.doFilter($scope.search);


查看完整回答
反對 回復(fù) 2021-11-12
?
慕斯王

TA貢獻1864條經(jīng)驗 獲得超2個贊

您可以在 ng-init 指令中指定應(yīng)該在頁面初始化時執(zhí)行的方法:

ng-init="doFilter({keywords: 'initial'})"


查看完整回答
反對 回復(fù) 2021-11-12
  • 2 回答
  • 0 關(guān)注
  • 117 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號