xm-select/docs/mds/XM03.md
2019-11-19 20:13:50 +08:00

920 B

默认选中

使用selected属性

:::demo 当然selected是选中, disabled是禁用

<div id="demo2" class="xm-select-demo"></div>

<script>
var demo2 = xmSelect.render({
	el: '#demo2', 
	data: [
		{name: '水果', value: 1, selected: true, disabled: true},
		{name: '蔬菜', value: 2, selected: true},
		{name: '桌子', value: 3, disabled: true},
		{name: '北京', value: 4},
	]
})
</script>

:::

使用initValue进行初始化

:::demo initValue的优先级大于选项中的selected

<div id="demo1" class="xm-select-demo"></div>

<script>
var demo5 = xmSelect.render({
	el: '#demo1', 
	initValue: [4],
	data: [
		{name: '水果', value: 1, selected: true, disabled: true},
		{name: '蔬菜', value: 2, selected: true},
		{name: '桌子', value: 3, disabled: true},
		{name: '北京', value: 4},
	]
})
</script>

:::