xm-select/docs/mds/ZM05.md

57 lines
854 B
Markdown
Raw Normal View History

2019-11-19 20:13:50 +08:00
## 动态数据
### 本地数据动态赋值
:::demo
```html
<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
```html
<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>
```
:::