xm-select/docs/mds/ZM05.md
2019-10-16 23:22:54 +08:00

867 B

动态数据

本地数据动态赋值

:::demo

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

<script>
var demo1 = xmSelect.render({
    el: '#demo1', 
    data: []
})

demo1.update({
    data: [
        {name: '张三', value: 1, selected: true},
        {name: '李四', value: 2, selected: true},
        {name: '王五', value: 3, disabled: true},
    ]
})

</script>

:::

远程数据动态赋值

:::demo

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

<script>
var demo2 = xmSelect.render({
    el: '#demo2', 
    toolbar: {show: true},
    data: []
})

axios({
    method: 'get',
    url: 'https://www.fastmock.site/mock/98228b1f16b7e5112d6c0c87921eabc1/xmSelect/search',
}).then(response => {
    var res = response.data;
    
    demo2.update({
        data: res.data,
        autoRow: true,
    })
});

</script>

:::