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

页面中




  
    项目
  
  
  
    
    
      
        
          
            {{item.title}}
            所在地区:{{item.address}}
            所属行业:{{item.industry}}
          
        
      
    
  
  
	

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');
}

你可能感兴趣的:(小程序)