收藏
回答

小程序下拉框赋值获取id和title?

废话不多说上代码

wxml代码

<view class="name">

<view>品牌:</view>

<view>

<picker bindchange="changeBrandType" value="{{indexBrandType}}" range="{{arrayBrandType}}" range-key="{{'title'}}" >

{{arrayBrandType[indexBrandType].title}}

</picker>

</view>

</view>


.js代码



/**

* 页面的初始数据

*/

data: {

arrayBrandType: [{ title: '服务质量', id: 1 }, { title: '服务品质', id: 2 }, { title: '服务速度', id: 25 }],

indexBrandType: 0, //值 同步的 显示的

},


/**

* 生命周期函数--监听页面加载

*/

onLoad: function (options) {

var that = this;

wx.request({

url: app.globalData.wPathApi + 'GetBrandType.ashx', data: {

strkey: app.globalData.strkey

},

header: { 'content-type': 'application/json' },

success: function (res) {

//console.log(res)arrayBrandTypeId

if (res.data.Result === 1) {

//赋值

that.setData({

arrayBrandType: res.data.Data

})


setTimeout(function () {

wx.hideLoading();

}, 1000)

}

else {

//

}

//

}

})

},

// 改变下拉选项

changeBrandType: function (event) {

var that = this;

this.setData({ //给变量赋值

indexBrandType: event.detail.value,

})

console.log('乔丹选的是', event.detail.value)//正常索引正常赋值

console.log('乔丹选的是', this.data.arrayBrandType[event.detail.value].title)

console.log('乔丹选的是', this.data.arrayBrandType[event.detail.value].id)

}

}


最后一次编辑于  2019-11-20
回答关注问题邀请回答
收藏

1 个回答

  • .
    .
    2019-11-20

    changeBrandType:function(e){

        console.log(e)

    }

    2019-11-20
    有用
    回复
登录 后发表内容
问题标签