第一重循环中,用wx:for-index保存categories的索引,第二种循环遍历post时,用这个索引来比较cat数组的catid和posd数组的id是否一致,大概如下: [代码]第一重:wx:for=[代码][代码]"{{categoriesList}}" wx:for-index="cat_idx"[代码] 第二重:wx:for="{{postList}}" 第二重循环里面判断两个变量相同则显示wx:if("categoriesList[cat_idx].id==postList[index].categories")
如何wx:for嵌套循环遍历两个不同的数组?其中已知两个数组中的id和categories值一致。已知存在有两个固定写法的API数组(下面)。 其中cat.api里的id值等于post.api里的categories值。需要在前端页面循环显示分类和分类下的文章。第二个循环不知道如何关联写法。请大神们看看 [代码]<block wx:key=[代码][代码]"id"[代码] [代码]wx:for=[代码][代码]"{{categoriesList}}"[代码][代码]>[代码][代码] [代码][代码]<view class=[代码][代码]"list-item"[代码][代码]>[代码][代码] [代码][代码]<view class=[代码][代码]"content-title"[代码] [代码]data-item=[代码][代码]"{{item.name}}"[代码] [代码]data-id=[代码][代码]"{{item.id}}"[代码] [代码]bindtap=[代码][代码]"redictIndex"[代码][代码]>[代码][代码] [代码][代码]<view class=[代码][代码]"topic-name"[代码][代码]>[代码][代码] [代码][代码]<text>{{item.name}}</text>[代码][代码] [代码][代码]</view>[代码][代码] [代码][代码]</view>[代码][代码] [代码][代码]<view class=[代码][代码]"common-list"[代码][代码]>[代码][代码] [代码][代码]<block wx:key=[代码][代码]"id"[代码] [代码]wx:for=[代码][代码]"{{postsList}}"[代码][代码]>[代码][代码] [代码][代码]<image src=[代码][代码]"{{item.post_medium_image}}"[代码] [代码]mode=[代码][代码]"aspectFill"[代码] [代码]class=[代码][代码]"cover"[代码][代码]></image>[代码][代码] [代码][代码]<view class=[代码][代码]"content-title"[代码][代码]>[代码][代码] [代码][代码]<text>{{item.title.rendered}}</text>[代码][代码] [代码][代码]</view> [代码][代码] [代码][代码]</block>[代码][代码] [代码][代码]</view>[代码][代码] [代码][代码]</view>[代码][代码]</block>[代码] 需要的前端效果: [图片] 文章分类cat.api。其中cat.api里的id值等于post.api里的categories值。 [代码][[代码][代码] [代码][代码]{[代码][代码] [代码][代码]"id"[代码][代码]: 112,[代码][代码] [代码][代码]"count"[代码][代码]: 7,[代码][代码] [代码][代码]"description"[代码][代码]: [代码][代码]""[代码][代码],[代码][代码] [代码][代码]"link"[代码][代码]: [代码][代码]"https://"[代码][代码],[代码][代码] [代码][代码]"name"[代码][代码]: [代码][代码]"分类CAT1"[代码][代码],[代码][代码] [代码][代码]"parent"[代码][代码]: 120,[代码][代码] [代码][代码]"meta"[代码][代码]: [],[代码][代码] [代码][代码]"category_thumbnail_image"[代码][代码]: [代码][代码]""[代码][代码] [代码][代码]},[代码][代码] [代码][代码]{[代码][代码] [代码][代码]"id"[代码][代码]: 113,[代码][代码] [代码][代码]"count"[代码][代码]: 0,[代码][代码] [代码][代码]"description"[代码][代码]: [代码][代码]""[代码][代码],[代码][代码] [代码][代码]"link"[代码][代码]: [代码][代码]"https://"[代码][代码],[代码][代码] [代码][代码]"name"[代码][代码]: [代码][代码]"分类CAT2"[代码][代码],[代码][代码] [代码][代码]"parent"[代码][代码]: 120,[代码][代码] [代码][代码]"meta"[代码][代码]: [],[代码][代码] [代码][代码]"category_thumbnail_image"[代码][代码]: [代码][代码]""[代码][代码] [代码][代码]},[代码][代码] [代码][代码]{[代码][代码] [代码][代码]"id"[代码][代码]: 126,[代码][代码] [代码][代码]"count"[代码][代码]: 4,[代码][代码] [代码][代码]"description"[代码][代码]: [代码][代码]""[代码][代码],[代码][代码] [代码][代码]"link"[代码][代码]: [代码][代码]"https://"[代码][代码],[代码][代码] [代码][代码]"name"[代码][代码]: [代码][代码]"分类CAT3"[代码][代码],[代码][代码] [代码][代码]"parent"[代码][代码]: 120,[代码][代码] [代码][代码]"meta"[代码][代码]: [],[代码][代码] [代码][代码]"category_thumbnail_image"[代码][代码]: [代码][代码]""[代码][代码],[代码][代码] [代码][代码]}[代码][代码]][代码] 文章post.api [代码][[代码][代码] [代码][代码]{[代码][代码] [代码][代码]"id"[代码][代码]: 1134,[代码][代码] [代码][代码]"date"[代码][代码]: [代码][代码]"2019-10-08T14:13:41"[代码][代码],[代码][代码] [代码][代码]"date_gmt"[代码][代码]: [代码][代码]"2019-10-08T06:13:41"[代码][代码],[代码][代码] [代码][代码]"type"[代码][代码]: [代码][代码]"post"[代码][代码],[代码][代码] [代码][代码]"link"[代码][代码]: [代码][代码]""[代码][代码],[代码][代码] [代码][代码]"title"[代码][代码]: {[代码][代码] [代码][代码]"rendered"[代码][代码]: [代码][代码]"文章1"[代码][代码] [代码][代码]},[代码][代码] [代码][代码]"excerpt"[代码][代码]: {[代码][代码] [代码][代码]"rendered"[代码][代码]: [代码][代码]"DESC1"[代码][代码],[代码][代码] [代码][代码]"protected"[代码][代码]: false[代码][代码] [代码][代码]},[代码][代码] [代码][代码]"author"[代码][代码]: 1,[代码][代码] [代码][代码]"categories"[代码][代码]: [[代码][代码] [代码][代码]112[代码][代码] [代码][代码]],[代码][代码] [代码][代码]"post_thumbnail_image"[代码][代码]: [代码][代码]"https://"[代码][代码],[代码] [代码] [代码][代码]},[代码][代码] [代码][代码]{[代码][代码] [代码][代码]"id"[代码][代码]: 1131,[代码][代码] [代码][代码]"date"[代码][代码]: [代码][代码]"2019-10-08T14:13:41"[代码][代码],[代码][代码] [代码][代码]"date_gmt"[代码][代码]: [代码][代码]"2019-10-08T06:13:41"[代码][代码],[代码][代码] [代码][代码]"type"[代码][代码]: [代码][代码]"post"[代码][代码],[代码][代码] [代码][代码]"link"[代码][代码]: [代码][代码]""[代码][代码],[代码][代码] [代码][代码]"title"[代码][代码]: {[代码][代码] [代码][代码]"rendered"[代码][代码]: [代码][代码]"文章2"[代码][代码] [代码][代码]},[代码][代码] [代码][代码]"excerpt"[代码][代码]: {[代码][代码] [代码][代码]"rendered"[代码][代码]: [代码][代码]"DESC2"[代码][代码],[代码][代码] [代码][代码]"protected"[代码][代码]: false[代码][代码] [代码][代码]},[代码][代码] [代码][代码]"author"[代码][代码]: 1,[代码][代码] [代码][代码]"categories"[代码][代码]: [[代码][代码] [代码][代码]112[代码][代码] [代码][代码]],[代码][代码] [代码][代码]"post_thumbnail_image"[代码][代码]: [代码][代码]"https://"[代码][代码],[代码][代码] [代码][代码]},[代码][代码] [代码][代码]{[代码][代码] [代码][代码]"id"[代码][代码]: 1128,[代码][代码] [代码][代码]"date"[代码][代码]: [代码][代码]"2019-10-08T14:13:41"[代码][代码],[代码][代码] [代码][代码]"date_gmt"[代码][代码]: [代码][代码]"2019-10-08T06:13:41"[代码][代码],[代码][代码] [代码][代码]"type"[代码][代码]: [代码][代码]"post"[代码][代码],[代码][代码] [代码][代码]"link"[代码][代码]: [代码][代码]""[代码][代码],[代码][代码] [代码][代码]"title"[代码][代码]: {[代码][代码] [代码][代码]"rendered"[代码][代码]: [代码][代码]"文章3"[代码][代码] [代码][代码]},[代码][代码] [代码][代码]"excerpt"[代码][代码]: {[代码][代码] [代码][代码]"rendered"[代码][代码]: [代码][代码]"DESC3"[代码][代码],[代码][代码] [代码][代码]"protected"[代码][代码]: false[代码][代码] [代码][代码]},[代码][代码] [代码][代码]"author"[代码][代码]: 1,[代码][代码] [代码][代码]"categories"[代码][代码]: [[代码][代码] [代码][代码]113[代码][代码] [代码][代码]],[代码][代码] [代码][代码]"post_thumbnail_image"[代码][代码]: [代码][代码]"https://"[代码][代码],[代码][代码] [代码][代码]},[代码][代码] [代码][代码]{[代码][代码] [代码][代码]"id"[代码][代码]: 1125,[代码][代码] [代码][代码]"date"[代码][代码]: [代码][代码]"2019-10-08T14:13:41"[代码][代码],[代码][代码] [代码][代码]"date_gmt"[代码][代码]: [代码][代码]"2019-10-08T06:13:41"[代码][代码],[代码][代码] [代码][代码]"type"[代码][代码]: [代码][代码]"post"[代码][代码],[代码][代码] [代码][代码]"link"[代码][代码]: [代码][代码]""[代码][代码],[代码][代码] [代码][代码]"title"[代码][代码]: {[代码][代码] [代码][代码]"rendered"[代码][代码]: [代码][代码]"文章4"[代码][代码] [代码][代码]},[代码][代码] [代码][代码]"excerpt"[代码][代码]: {[代码][代码] [代码][代码]"rendered"[代码][代码]: [代码][代码]"DESC4"[代码][代码],[代码][代码] [代码][代码]"protected"[代码][代码]: false[代码][代码] [代码][代码]},[代码][代码] [代码][代码]"author"[代码][代码]: 1,[代码][代码] [代码][代码]"categories"[代码][代码]: [[代码][代码] [代码][代码]113[代码][代码] [代码][代码]],[代码][代码] [代码][代码]"post_thumbnail_image"[代码][代码]: [代码][代码]"https://"[代码][代码],[代码][代码] [代码][代码]},[代码][代码] [代码][代码]{[代码][代码] [代码][代码]"id"[代码][代码]: 1022,[代码][代码] [代码][代码]"date"[代码][代码]: [代码][代码]"2019-10-08T14:13:41"[代码][代码],[代码][代码] [代码][代码]"date_gmt"[代码][代码]: [代码][代码]"2019-10-08T06:13:41"[代码][代码],[代码][代码] [代码][代码]"type"[代码][代码]: [代码][代码]"post"[代码][代码],[代码][代码] [代码][代码]"link"[代码][代码]: [代码][代码]""[代码][代码],[代码][代码] [代码][代码]"title"[代码][代码]: {[代码][代码] [代码][代码]"rendered"[代码][代码]: [代码][代码]"文章5"[代码][代码] [代码][代码]},[代码][代码] [代码][代码]"excerpt"[代码][代码]: {[代码][代码] [代码][代码]"rendered"[代码][代码]: [代码][代码]"DESC5"[代码][代码],[代码][代码] [代码][代码]"protected"[代码][代码]: false[代码][代码] [代码][代码]},[代码][代码] [代码][代码]"author"[代码][代码]: 1,[代码][代码] [代码][代码]"categories"[代码][代码]: [[代码][代码] [代码][代码]126[代码][代码] [代码][代码]],[代码][代码] [代码][代码]"post_thumbnail_image"[代码][代码]: [代码][代码]"https://"[代码][代码],[代码][代码] [代码][代码]},[代码][代码] [代码][代码]{[代码][代码] [代码][代码]"id"[代码][代码]: 1075,[代码][代码] [代码][代码]"date"[代码][代码]: [代码][代码]"2019-10-08T14:13:41"[代码][代码],[代码][代码] [代码][代码]"date_gmt"[代码][代码]: [代码][代码]"2019-10-08T06:13:41"[代码][代码],[代码][代码] [代码][代码]"type"[代码][代码]: [代码][代码]"post"[代码][代码],[代码][代码] [代码][代码]"link"[代码][代码]: [代码][代码]""[代码][代码],[代码][代码] [代码][代码]"title"[代码][代码]: {[代码][代码] [代码][代码]"rendered"[代码][代码]: [代码][代码]"文章6"[代码][代码] [代码][代码]},[代码][代码] [代码][代码]"excerpt"[代码][代码]: {[代码][代码] [代码][代码]"rendered"[代码][代码]: [代码][代码]"DESC6"[代码][代码],[代码][代码] [代码][代码]"protected"[代码][代码]: false[代码][代码] [代码][代码]},[代码][代码] [代码][代码]"author"[代码][代码]: 1,[代码][代码] [代码][代码]"categories"[代码][代码]: [[代码][代码] [代码][代码]126[代码][代码] [代码][代码]],[代码][代码] [代码][代码]"post_thumbnail_image"[代码][代码]: [代码][代码]"https://"[代码][代码],[代码][代码] [代码][代码]}[代码][代码]][代码]
2019-10-15这个方法我试过,编译报错 util.js 中怎么写, episodeListT: [ { title: 'S01E01', }, { title: 'S01E02', } ] module.exports = { formatTime: formatTime } 编译报错如下。 WAService.js:1 Uncaught ReferenceError: episodeListT is not defined at season_info.js:13 at require (WAService.js:1) at WAService.js:1 at season.js:4 at require (WAService.js:1) at <anonymous>:35:7 at HTMLScriptElement.scriptLoaded (appservice?t=1567840945601:1184) at HTMLScriptElement.script.onload (appservice?t=1567840945601:1196)
如何在一个js中引用另外一个js中的data?小程序数据比较多,放在data段会导致function被放到很下面,有没有办法单独将data放到一个js中,由主js调用?
2019-09-07