Skip to content

Commit 6b03ab1

Browse files
committed
Use Vue method to filter search listings
1 parent 271649c commit 6b03ab1

File tree

2 files changed

+4
-24
lines changed

2 files changed

+4
-24
lines changed

src/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ <h3 class="center-text">
2323
</h3>
2424
</header>
2525
<body>
26-
<div class=center-text>
27-
<input type="text" id="searchbox" onkeyup="filterRows()" placeholder="search for a service">
28-
</div>
2926
<div id="app">
27+
<div class=center-text>
28+
<input type="search" id="searchbox" placeholder="Search APIs" autocomplete="off" spellcheck="false" tabindex="0" v-model="filter">
29+
</div>
3030
<div style="overflow-x:auto;">
3131
<table id="entries">
3232
<thead>
@@ -39,7 +39,7 @@ <h3 class="center-text">
3939
</tr>
4040
</thead>
4141
<tbody>
42-
<tr v-for="item in items">
42+
<tr v-for="item in items" v-show="filtered(item)">
4343
<td><a :href="item.Link">{{ item.API }}</a></td>
4444
<td>{{ item.Description }}</td>
4545
<td>{{ (item.Auth) ? item.Auth : '-' }}</td>

src/scripts.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,3 @@ new Vue({
3434
}
3535
}
3636
}).$mount('#app');
37-
38-
function filterRows() {
39-
var input, filter, table, tr, td, i;
40-
input = document.getElementById("searchbox");
41-
filter = input.value.toUpperCase();
42-
table = document.getElementById("entries");
43-
tr = table.getElementsByTagName("tr");
44-
45-
// Loop through all table rows and hide those who don't match the search
46-
for (i = 0; i < tr.length; i++) {
47-
td = tr[i].getElementsByTagName("td")[0];
48-
if (td) {
49-
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
50-
tr[i].style.display = "";
51-
} else {
52-
tr[i].style.display = "none";
53-
}
54-
}
55-
}
56-
}

0 commit comments

Comments
 (0)