wxml文件
<view class="container">
<view class="content">
<view class="all-food">
<view class="food">全部食物</view>
<scroll-view class="food-scroll" scroll-y="true" scroll-into-view="{
{toView}}" scroll-with-animation="true">
<view class="food-list">
<view wx:for="{
{foodList}}" wx:key="{
{index}}" id="{
{'food'+index}}" data-title="{
{item.title}}">
<view class="nav-text">
<text>{
{item.title}}</text>
</view>
<view class="show-food">
<text wx:for="{
{item.lists}}" wx:key="{
{index}}">{
{item}}</text>
</view>
</view>
</view>
</scroll-view>
</view>
<view class="search-nav" bindtouchstart="touchStart" bindtouchmove="touchMove" bindtouchend="touchEnd">
<text bindtap="foodScroll" data-index="{
{index}}" wx:for="{
{searchNav}}" wx:key="{
{index}}">{
{item}}</text>
</view>
</view>
</view>
js文件
let foodList = require('../../utils/common');
Page({
/**
* 页面的初始数据
*/
data: {
foodList:[],
toView:'',
searchNav:[]
},
getFoodList(){
let searchNav = this.data.searchNav
for(let i in foodList.foodList){
searchNav.push(foodList.foodList[i].title)
}
this.setData({
foodList:foodList.foodList,
searchNav:searchNav
})
},
foodScroll