Commit f5ecd1677700cd2a0767ee60d9320f5625589a6f

Authored by 梁灏
1 parent c35c53d8

fixed #186

fixed #186
src/components/select/option-group.vue
1 1 <template>
2   - <li :class="[prefixCls + '-wrap']">
  2 + <li :class="[prefixCls + '-wrap']" v-show="!hidden">
3 3 <div :class="[prefixCls + '-title']">{{ label }}</div>
4 4 <ul>
5   - <li :class="[prefixCls]"><slot></slot></li>
  5 + <li :class="[prefixCls]" v-el:options><slot></slot></li>
6 6 </ul>
7 7 </li>
8 8 </template>
... ... @@ -18,8 +18,30 @@
18 18 },
19 19 data () {
20 20 return {
21   - prefixCls: prefixCls
  21 + prefixCls: prefixCls,
  22 + hidden: false // for search
22 23 };
  24 + },
  25 + methods: {
  26 + queryChange () {
  27 + this.$nextTick(() => {
  28 + const options = this.$els.options.querySelectorAll('.ivu-select-item');
  29 + let hasVisibleOption = false;
  30 + for (let i = 0; i < options.length; i++) {
  31 + if (options[i].style.display !== 'none') {
  32 + hasVisibleOption = true;
  33 + break;
  34 + }
  35 + }
  36 + this.hidden = !hasVisibleOption;
  37 + });
  38 + }
  39 + },
  40 + events: {
  41 + 'on-query-change' () {
  42 + this.queryChange();
  43 + return true;
  44 + }
23 45 }
24 46 };
25 47 </script>
... ...
test/routers/select.vue
1 1 <template>
2   - <Row style="width: 400px">
3   - <i-col span="12" style="padding-right:10px">
4   - <i-select :model.sync="model11" filterable>
5   - <i-option v-for="item in cityList" :value="item.value">{{ item.label }}</i-option>
6   - </i-select>
7   - </i-col>
8   - <i-col span="12">
9   - <i-select :model.sync="model12" filterable multiple>
10   - <i-option v-for="item in cityList" :value="item.value">{{ item.label }}</i-option>
11   - </i-select>
12   - </i-col>
13   - </Row>
  2 + <i-select :model.sync="model7" style="width:200px"
  3 + filterable>
  4 + <i-option v-for="item in cityList | limitBy 3" :value="item.value">{{ item.label }}</i-option>
  5 + <i-option v-for="item in cityList | limitBy 3 3" :value="item.value">{{ item.label }}</i-option>
  6 + </i-select>
14 7 </template>
15 8 <script>
16 9 export default {
... ... @@ -42,8 +35,7 @@
42 35 label: '重庆市'
43 36 }
44 37 ],
45   - model11: '',
46   - model12: []
  38 + model7: ''
47 39 }
48 40 }
49 41 }
... ...