@@ -12,6 +12,8 @@ Vue.prototype.$http = http
12
12
new Vue ( {
13
13
data : {
14
14
subreddit : '/r/funny' ,
15
+ page_num : 1 ,
16
+ last_page : '' ,
15
17
items : [ ]
16
18
} ,
17
19
@@ -24,18 +26,14 @@ new Vue({
24
26
<stack-layout orientation="horizontal" class="list-group-item">
25
27
<image :src="item.image" class="thumb"></image>
26
28
<stack-layout>
27
- <label class="list-group-item-heading" :text="item.title" textWrap ="true"></label>
28
- <label class="list-group-item-text" text="The rest of the content" textWrap ="true"></label>
29
+ <label class="list-group-item-heading" :text="item.title" text-wrap ="true"></label>
30
+ <label class="list-group-item-text" text="The rest of the content" text-wrap ="true"></label>
29
31
</stack-layout>
30
32
</stack-layout>
31
33
</template>
32
- <template name="active " scope="item">
34
+ <template name="page " scope="item">
33
35
<stack-layout orientation="horizontal" class="list-group-item active">
34
- <image :src="item.image" class="thumb"></image>
35
- <stack-layout>
36
- <label class="list-group-item-heading" :text="item.title" textWrap="true"></label>
37
- <label class="list-group-item-text" text="The rest of the content" textWrap="true"></label>
38
- </stack-layout>
36
+ <label :text="item.title"></label>
39
37
</stack-layout>
40
38
</template>
41
39
</list-view>
@@ -80,26 +78,12 @@ new Vue({
80
78
} ,
81
79
82
80
onLoadMoreItems ( e ) {
83
- console . log ( 'Loading (3) more items' )
84
- this . items . push ( {
85
- title : 'Foo loaded @ ' + new Date ( ) . toTimeString ( ) ,
86
- image : this . items [ 0 ] . image ,
87
- fullImage : this . items [ 0 ] . fullImage
88
- } ,
89
- {
90
- title : 'Bar loaded @ ' + new Date ( ) . toTimeString ( ) ,
91
- image : this . items [ 1 ] . image ,
92
- fullImage : this . items [ 1 ] . fullImage
93
- } ,
94
- {
95
- title : 'Baz loaded @ ' + new Date ( ) . toTimeString ( ) ,
96
- image : this . items [ 2 ] . image ,
97
- fullImage : this . items [ 2 ] . fullImage
98
- } )
81
+ console . log ( 'Loading more items' )
82
+ return this . fetchItems ( )
99
83
} ,
100
84
101
85
templateSelector ( item ) {
102
- return item . $index === 0 ? 'active ' : 'default'
86
+ return item . type === 'page' ? 'page ' : 'default'
103
87
} ,
104
88
105
89
chooseSubreddit ( ) {
@@ -117,14 +101,23 @@ new Vue({
117
101
} ,
118
102
119
103
fetchItems ( ) {
120
- this . $http . getJSON ( `https://www.reddit.com/${ this . subreddit } .json` ) . then ( ( res ) => {
121
- this . items = res . data . children . map ( ( item ) => {
122
- return {
104
+ this . $http . getJSON ( `https://www.reddit.com/${ this . subreddit } .json?limit=10&count=10&after=${ this . last_page } ` ) . then ( ( res ) => {
105
+ this . items . push ( {
106
+ title : 'Page ' + this . page_num ,
107
+ type : 'page'
108
+ } )
109
+ res . data . children . forEach ( ( item ) => {
110
+ this . items . push ( {
123
111
title : item . data . title ,
124
112
image : item . data . thumbnail ,
125
- fullImage : item . data . preview . images [ 0 ] . source . url
126
- }
113
+ fullImage : item . data . preview . images [ 0 ] . source . url ,
114
+ type : 'entry'
115
+ } )
127
116
} )
117
+ this . last_page = res . data . after
118
+ this . page_num ++ ;
119
+
120
+ console . log ( 'Loaded more items' )
128
121
} ) . catch ( ( err ) => {
129
122
console . log ( 'err..' + err )
130
123
} )
0 commit comments