欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序picker組件關(guān)于objectArray數(shù)據(jù)類型的綁定方法

 更新時(shí)間:2019年03月13日 08:22:55   作者:追逐時(shí)光  
這篇文章主要介紹了微信小程序picker組件關(guān)于objectArray數(shù)據(jù)類型的綁定方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

一、前言:

我發(fā)現(xiàn)很多的同學(xué)都在抱怨說(shuō)微信小程序的picker的mode = selector/mode = multiSelector 無(wú)法實(shí)現(xiàn)Object Array數(shù)據(jù)類型的綁定,其實(shí)很多人就想要和html中的下拉選中的通過(guò)選中獲取vaule中的屬性值,其實(shí)認(rèn)真查看微信picker組件詳解的都知道其實(shí)是可以實(shí)現(xiàn)的,只不過(guò)微信給的實(shí)例是array的實(shí)例而object array實(shí)例是留給大家去動(dòng)手的喲,在這里我主要介紹的mode=selector 的objectArray實(shí)現(xiàn)。

二、介紹:

 普通選擇器:mode = selector

屬性名 類型 默認(rèn)值 說(shuō)明
range Array / Object Array [] mode為 selector 或 multiSelector 時(shí),range 有效
range-key String 當(dāng) range 是一個(gè) Object Array 時(shí),通過(guò) range-key 來(lái)指定 Object 中 key 的值作為選擇器顯示內(nèi)容
value Number 0 value 的值表示選擇了 range 中的第幾個(gè)(下標(biāo)從 0 開(kāi)始)
bindchange EventHandle value 改變時(shí)觸發(fā) change 事件,event.detail = {value: value}
disabled Boolean false 是否禁用

微信picker組件詳解: https://developers.weixin.qq.com/miniprogram/dev/component/picker.html?search-key=picker

首先我的數(shù)據(jù)格式是:[{ name: '服務(wù)質(zhì)量', id: 20 }, { name: '服務(wù)品質(zhì)', id: 24 }, { name: '服務(wù)速度', id: 25}]

.wxml頁(yè)代碼:

//其中range為數(shù)據(jù)源,value為下標(biāo)索引,bindchange為change改變事件
<picker range='{{type}}' value='{{idx}}' bindchange='Change' range-key="name" data-id='{{type[index].id}}'>
<view class='picker'>{{type[index].name}}</view>
</picker>

.js代碼:

/**
  * 頁(yè)面的初始數(shù)據(jù)
  */
 data: {
  type: [{ name: '服務(wù)質(zhì)量', id: 20 }, { name: '服務(wù)品質(zhì)', id: 24 }, { name: '服務(wù)速度', id: 25}],
  index: 0,//索引
 },
 Change: function (e) {

  console.log('picker發(fā)送選擇改變,索引值為', e.detail.value)
  console.log("選中的id值:"+e.target.dataset.id)
  console.log(e);
  this.setData({

   index: e.detail.value

  })

 }

頁(yè)面效果和輸出結(jié)果:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論