小程序之 列表页的数据遍历展示

页面中

<view class="container">


  <view class="list-tab flexR" catchtap='toggleView'>
    <view class="{{nowRole==0?'checked-item':''}}" data-index="0">项目</view>
  </view>
  <!--列表展示  -->
  <swiper  bindchange="toggleSwiper" current='{{currentIndex}}'>
    
    <swiper-item>
      <scroll-view  scroll-y="true" style="height:calc(100vh - 252px);"  bindscrolltolower="bindDownLoad" id="gn" class="investment-people-list flexC">
        <view class="item flexR" wx:for="{{contentlistn}}" bindtap='toDetail' data-type="gn" data-id="{{item.id}}">
          <view class="people-info flexC">
            <view>{{item.title}}</view>
            <view>所在地区:{{item.address}}</view>
            <view>所属行业:{{item.industry}}</view>
          </view>
        </view>
      </scroll-view>
    </swiper-item>
  </swiper>
  
</view>	

js 中

//获取应用实例
const app = getApp();
// 引入 js
var xtrequest = require('../../utils/xtrequest.js')
Page({
  data: {
    pagen: 1,
    pagey: 1,
    totalpage: '',
    nowRole: 0,
    currentIndex: 0,
    app_parameter: '',
    contentlistn: [],  // 页面分配数据,在这定义空数据,下面方法中分配数据
    loadMoreData: '',
    hideBottom: true,
    refreshTime: '', // 刷新的时间 
  },
  // 加载页面时 触发的操作
  onLoad: function () {
    this.setData({
      app_parameter: wx.getStorageSync('app_parameter')
    })
    var that = this;
    wx.request({
      url: 'https://...com/Wapi/Index/index',      // 请求接口返回列表数据
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        that.setData({
          contentlistn: res.data.guonei,           // 页面分配数据
        });
      }
    })

  },
  onshow: function () {

  },
  //toggleView
  toggleView: function (event) {
    let that = this;
    let currentIndex = that.data;
    currentIndex = event.target.dataset.index;
    that.setData({
      currentIndex
    })
  },
  //swiper切换
  toggleSwiper: function (event) {
    let that = this;
    let nowRole = that.data;
    nowRole = event.detail.current;
    that.setData({
      nowRole
    })
  },
  //跳转到详情页
  toDetail: (event) => {
    let type = event.currentTarget.dataset.type;
    var id = event.currentTarget.dataset.id;
    let url;
    if (type == "gn") {
      url = "/pages/detail/detail?id=" + id + "&type=" + type;
    } else {
      url = "/pages/detail/detail?id=" + id + "&type=" + type;
    }
    wx.navigateTo({
      url: url,
    })
  },
  // tab切换
  toTabPage: function (e) {
    toTabPage(e)
  },
  launchAppError: function (e) {
    console.log(e.detail.errMsg)
  },
  toApp: function () {
    app.toApp();
  },
  
  bindDownLoad: function (options) {
    var that = this;
    // console.log(options);
    var id = options.currentTarget.id
    if (id == 'gn') {
      var page = this.data.pagen
      var content = this.data.contentlistn
      xtrequest.xtrequest.getItemList({
        page: page,
        id: id,
        content: content,
        success: function (res, shuju) {
          if (shuju.status == 0) {
            that.setData({
              loadMoreData: shuju.error,
              hideBottom: false
            })
            setTimeout(function () {
              that.setData({
                hideBottom: true
              })
            }, 3000)
            return false
          }
          that.setData({
            contentlistn: shuju.item,
            pagen: shuju.page
          })
        }

  })
}
},
})

控制器

public function index() {
    
	$id=I("get.id",0,'intval');
	
	$project_model=M("project");
	$project=$project_model->where('status=1')->limit(6)->select();
	// 返回 列表数据
    $info=array(
        "guonei"=>$project
        );
	if(empty($info)){
        $data=array(
            "status"=>0,
            "message"=>"数据异常",
            );
        $data=json_encode($data,true);
	}
    $this->ajaxReturn($info,'JSON');
}
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值