Skip to content

Commit 4dac231

Browse files
committed
Create a filter to filter words
1 parent dc0c49f commit 4dac231

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

app/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
<body ng-app="abstackVarLib" ng-controller="mainCtrl">
1111
<header>
1212
Abstack Tech Variables Library
13-
<input type="text" class="search-box" placeholder="Type some keywords...">
13+
<input type="text" class="search-box" placeholder="Type some keywords..." ng-model="keywords">
1414
</header>
1515
<ul class="word-list ng-hide" ng-show="wordsList">
16-
<li ng-repeat="word in wordsList">
16+
<li ng-repeat="word in wordsList | keywords: keywords">
1717
<h3>
1818
<button class="btn-copy">COPY</button>
1919
<a target="_blank" ng-href="{{ word.url?word.url: 'http://www.dict.cn/' + word.word }}" ng-bind="word.word"></a>

app/json/words.json

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,23 @@
55
"tags": ["设置", "设定", "偏好"]
66
},
77
{
8-
"word": "settings",
9-
"url": "http://www.dict.cn/settings",
10-
"tags": ["设置", "设定", "偏好"]
11-
},
12-
{
13-
"word": "settings",
14-
"url": "http://www.dict.cn/settings",
15-
"tags": ["设置", "设定", "偏好"]
8+
"word": "feedback",
9+
"tags": ["建议", "反馈", "投诉", "意见", "改进"]
1610
},
1711
{
18-
"word": "settings",
19-
"url": "http://www.dict.cn/settings",
20-
"tags": ["设置", "设定", "偏好"]
12+
"word": "project",
13+
"tags": ["项目", "", "工程"]
2114
},
2215
{
23-
"word": "settings",
24-
"url": "http://www.dict.cn/settings",
25-
"tags": ["设置", "设定", "偏好"]
16+
"word": "dashboard",
17+
"tags": ["仪表盘", "概览", "主页", "监控"]
2618
},
2719
{
28-
"word": "settings",
29-
"url": "http://www.dict.cn/settings",
30-
"tags": ["设置", "设定", "偏好"]
20+
"word": "redirect",
21+
"tags": ["跳转", "转到"]
3122
},
3223
{
33-
"word": "settings",
34-
"url": "http://www.dict.cn/settings",
35-
"tags": ["设置", "设定", "偏好"]
24+
"word": "following",
25+
"tags": ["关注", "正在关注", "关心"]
3626
}
3727
]

app/scripts/app.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@
44
* Description: main
55
*/
66
angular.module('abstackVarLib', [])
7+
.filter('keywords', function(){
8+
return function(input, type){
9+
if(!type)
10+
return input;
11+
12+
var temp = [];
13+
for(var i = 0;i<input.length;i++){
14+
if(input[i].tags.join().indexOf(type) != -1)
15+
temp.push(input[i]);
16+
}
17+
18+
return temp;
19+
}
20+
})
721
.controller('mainCtrl', ['$http', '$scope', function($http, $scope){
822

923
$http.get('/json/words.json')

0 commit comments

Comments
 (0)