File tree Expand file tree Collapse file tree 2 files changed +43
-30
lines changed
Expand file tree Collapse file tree 2 files changed +43
-30
lines changed Original file line number Diff line number Diff line change 2222
2323 < hr >
2424
25- < h4 > Routes</ h4 >
2625 < p >
2726 Here are the resources that JSON Server has loaded:
2827 </ p >
29- < ul id ="resources "> loading, please wait...</ ul >
28+ < div id ="resources "> loading, please wait...</ div >
3029
3130 < div id ="custom-routes "> </ div >
3231
@@ -63,33 +62,7 @@ <h4>Issues</h4>
6362 </ p >
6463 </ div >
6564
66- < script
67- src ="https://code.jquery.com/jquery-3.0.0.min.js "
68- integrity ="sha256-JmvOoLtYsmqlsWxa7mDSLMwa6dZ9rrIdtrrVYRnDRH0= " crossorigin ="anonymous "> </ script >
69- < script >
70- $ ( function ( ) {
71- $ . get ( 'db' ) . then ( function ( data ) {
72- var el = $ ( '#resources' )
73-
74- el . empty ( )
75-
76- $ . each ( data , function ( key , value ) {
77- el . append ( '<li><a href="' + key + '">' + key + '</a></li>' )
78- } )
79- } )
80-
81- $ . get ( '__rules' ) . then ( function ( data ) {
82- var el = $ ( '#custom-routes' )
83-
84- el . append ( '<p>And the custom routes:</p>' )
85- . append ( '<ul id="custom-routes-list">' )
86-
87- var listEl = $ ( '#custom-routes-list' )
88- $ . each ( data , function ( key , value ) {
89- listEl . append ( '<li>' + key + ' → ' + value + '</li>' )
90- } )
91- } )
92- } )
93- </ script >
65+ < script src ="https://unpkg.com/mithril/mithril.min.js "> </ script >
66+ < script src ="main.js "> </ script >
9467 </ body >
9568</ html >
Original file line number Diff line number Diff line change 1+ // Resource list
2+ var resources = [ ]
3+
4+ m . request ( 'db' ) . then ( function ( data ) {
5+ resources = Object . keys ( data )
6+ } )
7+
8+ m . mount (
9+ document . getElementById ( 'resources' ) ,
10+ {
11+ view : function ( ) {
12+ return m ( 'ul' , resources . map ( function ( resource ) {
13+ return m ( 'li' ,
14+ m ( 'a' , { href : resource } , resource )
15+ )
16+ } ) )
17+ }
18+ }
19+ )
20+
21+ // Custom routes
22+ var rules = { }
23+
24+ m . request ( '__rules' ) . then ( function ( data ) {
25+ rules = data
26+ } )
27+
28+ m . mount (
29+ document . getElementById ( 'custom-routes' ) ,
30+ {
31+ view : function ( ) {
32+ return [
33+ m ( 'p' , 'And the custom routes:' ) ,
34+ m ( 'ul' , Object . keys ( rules ) . map ( function ( rule ) {
35+ return m ( 'li' , rule + ' → ' + rules [ rule ] )
36+ } ) )
37+ ]
38+ }
39+ }
40+ )
You can’t perform that action at this time.
0 commit comments