带搜索功能的选择器

<template>
	<view>
		<view><button @tap="btnSee">查看</button></view>
		<song-data-picker v-model="moduleValue1" :localdata="items1" popup-title="请选择班级" :openSearch="true"
			@change="onchange" @nodeclick="onnodeclick" :searchFn="mySearchFn"></song-data-picker>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				items1: [{
						text: "吉林市水务集团",
						value: 1
					},
					{
						text: "吉林市档案馆",
						value: 2
					},
					{
						text: "吉林市外事局",
						value: 3
					},
					{
						text: "吉林市联通公司",
						value: 4
					},
					{
						text: "市委办公厅",
						value: 5
					},
					{
						text: "吉林市政协",
						value: 6
					},
					{
						text: "秘书处",
						value: 7
					},
					{
						text: "人事劳资处党支部",
						value: 8
					},
					{
						text: "机关车队党支部",
						value: 9
					},
					{
						text: "内司委",
						value: 10
					},
					{
						text: "吉林市政协",
						value: 11
					},
					{
						text: "法制委党支部",
						value: 12
					},
					{
						text: "研究室党支部",
						value: 13
					}
				],
				moduleValue1: [],
				items: [{
						text: "一年级",
						value: "1-0",
						children: [{
								text: "1.1班",
								value: "1-1"
							},
							{
								text: "1.2班",
								value: "1-2"
							}
						]
					},
					{
						text: "二年级",
						value: "2-0",
						children: [{
							text: "2.1班",
							value: "2-1"
						}]
					},
					{
						text: "三年级",
						value: "3-0"
					}
				],
				moduleValue: [{
						text: "一年级",
						value: "1-0"
					},
					{
						text: "1.2班",
						value: "1-2"
					}
				]
			}
		},
		onLoad() {

		},
		methods: {
			btnSee() {
				// this.moduleValue=[];
				console.log(this.moduleValue1)
			},
			mySearchFn(searchList, searchWord) {
				// console.log(searchList)
				// console.log(searchWord)
				return searchList.filter(x => x.text.includes(searchWord));	
				// if(searchWord == "")
				// {
				// 	return [];
				// }else{
				// 	return searchList.filter(x => x.searctText.indexOf(searchWord));
				// }
				// let lResult = [];
				
				// for(let item of searchList){
				// 	console.log(item)
				// 	if(item.text.includes(searchWord)){
				// 		lResult.push(item)
				// 	}
				// }
				
				// return lResult;
			},
			onchange(e) {
				// const value = e.detail.value
				// console.log(value)
			},
			onnodeclick(node) {
				// console.log('onnodeclick=')
				// console.log(node)
			}
		}
	}
</script>

https://ext.dcloud.net.cn/plugin?id=4290

posted @ 2022-06-26 13:05  寒冷的雨呢  阅读(205)  评论(0编辑  收藏  举报