Commit d87ce40a740534e9876c228be2fcfebb1e902af3
1 parent
6f8608bb
update Select
Showing
2 changed files
with
26 additions
and
10 deletions
Show diff stats
examples/routers/select.vue
1 | 1 | <template> |
2 | - <div style="width: 200px;margin: 100px;"> | |
3 | - {{ model }} | |
4 | - <i-select v-model="model" filterable remote :remote-method="remoteMethod" :loading="loading" clearable style="width:200px"> | |
5 | - <i-option v-for="option in options" :value="option.value" :key="option">{{option.label}}</i-option> | |
6 | - </i-select> | |
7 | - <!--<Button @click="handleAdd">+</Button>--> | |
8 | - </div> | |
2 | + <Row> | |
3 | + <i-col span="4">{{model}}</i-col> | |
4 | + <i-col span="8"> | |
5 | + <i-select v-model="model" multiple filterable remote :remote-method="remoteMethod" :loading="loading" clearable> | |
6 | + <i-option v-for="option in options" :value="option.value" :key="option">{{option.label}}</i-option> | |
7 | + </i-select> | |
8 | + </i-col> | |
9 | + </Row> | |
9 | 10 | </template> |
10 | 11 | |
11 | 12 | <script> |
12 | 13 | export default { |
13 | 14 | data () { |
14 | 15 | return { |
15 | - model: '', | |
16 | + model: [], | |
16 | 17 | options: [ |
17 | 18 | |
18 | 19 | ], | ... | ... |
src/components/select/select.vue
... | ... | @@ -300,7 +300,7 @@ |
300 | 300 | }, |
301 | 301 | updateMultipleSelected (init = false, slot = false) { |
302 | 302 | if (this.multiple && Array.isArray(this.model)) { |
303 | - let selected = []; | |
303 | + let selected = this.remote ? this.selectedMultiple : []; | |
304 | 304 | |
305 | 305 | for (let i = 0; i < this.model.length; i++) { |
306 | 306 | const model = this.model[i]; |
... | ... | @@ -317,7 +317,16 @@ |
317 | 317 | } |
318 | 318 | } |
319 | 319 | |
320 | - this.selectedMultiple = selected; | |
320 | + const selectedArray = []; | |
321 | + const selectedObject = {}; | |
322 | + selected.forEach(item => { | |
323 | + if (!selectedObject[item.value]) { | |
324 | + selectedArray.push(item); | |
325 | + selectedObject[item.value] = 1; | |
326 | + } | |
327 | + }); | |
328 | + | |
329 | + this.selectedMultiple = this.remote ? selectedArray : selected; | |
321 | 330 | |
322 | 331 | if (slot) { |
323 | 332 | let selectedModel = []; |
... | ... | @@ -340,6 +349,12 @@ |
340 | 349 | if (this.disabled) { |
341 | 350 | return false; |
342 | 351 | } |
352 | + | |
353 | + if (this.remote) { | |
354 | + const tag = this.model[index]; | |
355 | + this.selectedMultiple = this.selectedMultiple.filter(item => item.value !== tag); | |
356 | + } | |
357 | + | |
343 | 358 | this.model.splice(index, 1); |
344 | 359 | |
345 | 360 | if (this.filterable && this.visible) { | ... | ... |