默认选中
使用selected
属性
当然selected
是选中, disabled
是禁用
html
<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进行初始化
initValue
的优先级大于选项中的selected
html
<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>