duidui_mini_program/pages/singledouble/singledouble.js
2026-03-27 10:41:46 +08:00

73 lines
1.8 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Page({
/**
* 页面的初始数据
*/
data: {
list:[{"id":"452113a3","name":"肥肥","active":''},
{"id":"a1b931a0","name":"滚滚","active":''},
{"id":"115af7f9","name":"圆圆","active":''},
{"id":"60fe875c","name":"胖胖","active":''},
{"id":"8f100654","name":"嘟嘟","active":''}],
type:[
{ id:'sgyl',name:'单选11111',active:false},
{ id:'js',name:'单选22222',active:false},
{ id:'shjjfz',name:'单选33333',active:false},
{ id:'sbhqs',name:'单选4444',active:false},
{ id:'ldmf',name:'单选5555',active:false},
{ id:'xfgw',name:'单选66666',active:false}
]
},
//单选
bindActive(e){
let arr = this.data.type.map(item=>{
if(item.id===e.currentTarget.dataset.id){
item.active=!item.active
}else{
item.active=false
}
return item
})
this.setData({type:arr});
this.getPeopleInfo();
},
//多选
bindList(e){
let index=e.currentTarget.dataset.id;
let arr=this.data.list.map(item=>{
if(item.id == index && item.active == ""){
item.active="active";
}else if(item.id == index){
item.active="";
}
return item
})
this.setData({list:arr});
this.getPeopleInfo();
},
//获取id
getPeopleInfo(){
let ids=this.data.list.filter( item=> item.active == 'active').map(item => item.id);
let dx=this.data.type.filter(item => item.active == true).map(item=>item.id);
console.log('多选Id'+ids)
console.log('单选Id'+dx);
},
onLoad: function (options) {
var arrSimple=new Array('A','D','C','B');
arrSimple.sort();
console.log(arrSimple);
var strList = ['A', 'C', 'D', 'B'];
strList.sort((a, b) => {
return a.localeCompare(b);
});
console.log(strList);
},
})