|
1 |
| - loadJSON(function(response) { |
2 |
| - var items = JSON.parse(response); |
3 |
| - new Vue({ |
4 |
| - data: { |
5 |
| - filter: '' |
6 |
| - }, |
7 |
| - computed: { |
8 |
| - data() { |
9 |
| - return items.entries; |
10 |
| - } |
11 |
| - }, |
12 |
| - methods: { |
13 |
| - filtered(item) { |
14 |
| - let show = true; |
| 1 | +new Vue({ |
| 2 | + data: { |
| 3 | + filter: '', |
| 4 | + items: '' |
| 5 | + }, |
| 6 | + created() { |
| 7 | + fetch('https://raw.githubusercontent.com/toddmotto/public-apis/master/json/entries.min.json') |
| 8 | + .then(data => data.json()) |
| 9 | + .then(data => { |
| 10 | + this.items = data.entries; |
| 11 | + }) |
| 12 | + }, |
| 13 | + methods: { |
| 14 | + filtered(item) { |
| 15 | + let show = true; |
| 16 | + |
| 17 | + if(this.filter.length) { |
15 | 18 |
|
16 |
| - if(this.filter.length) { |
17 |
| - |
18 |
| - show = false; |
19 |
| - |
20 |
| - let filterKeyword = this.filter.toLowerCase(); |
21 |
| - |
22 |
| - Object.keys(item).map(function(key) { |
23 |
| - if(typeof item[key] === 'string') { |
24 |
| - let value = item[key].toString().toLowerCase(); |
25 |
| - |
26 |
| - if(value.includes(filterKeyword)) { |
27 |
| - show = true; |
28 |
| - $( "th" ).addClass( "lol" ); |
29 |
| - } |
30 |
| - } |
| 19 | + show = false; |
| 20 | + |
| 21 | + let filterKeyword = this.filter.toLowerCase(); |
| 22 | + |
| 23 | + Object.keys(item).map(function(key) { |
| 24 | + if(typeof item[key] === 'string') { |
| 25 | + let value = item[key].toString().toLowerCase(); |
31 | 26 |
|
32 |
| - }); |
33 |
| - } |
34 |
| - return show; |
| 27 | + if(value.includes(filterKeyword)) { |
| 28 | + show = true; |
| 29 | + $( "th" ).addClass( "lol" ); |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + }); |
35 | 34 | }
|
| 35 | + return show; |
36 | 36 | }
|
37 |
| - }).$mount('#app'); |
38 |
| -}); |
39 |
| - |
40 |
| -function loadJSON(callback) { |
41 |
| - var xobj = new XMLHttpRequest(); |
42 |
| - xobj.overrideMimeType("application/json"); |
43 |
| - xobj.open('GET', 'https://raw.githubusercontent.com/toddmotto/public-apis/master/json/entries.min.json', true); |
44 |
| - xobj.onreadystatechange = function () { |
45 |
| - if (xobj.readyState == 4 && xobj.status == "200") { |
46 |
| - // Required use of an anonymous callback as .open will NOT return a value |
47 |
| - // but simply returns undefined in asynchronous mode |
48 |
| - callback(xobj.responseText); |
49 |
| - } |
50 |
| - }; |
51 |
| - xobj.send(null); |
52 |
| - } |
| 37 | + } |
| 38 | +}).$mount('#app'); |
53 | 39 |
|
54 | 40 | function filterRows() {
|
55 | 41 | var input, filter, table, tr, td, i;
|
|
0 commit comments