Element: Select does not support default object value

Created on 17 Jan 2017  ·  8Comments  ·  Source: ElemeFE/element

Steps to reproduce

Add a component el-select in a component that should represent a selection among objects:

<el-select v-model="objectValue">
  <el-option v-for="item in items" :label="item.id" :value="item"></el-option>
</el-select>

and the data defined as

data() {
  return {
    objectValue : {
      id : "a",
      attr1 : 0,
      attr2 : 1
    },
    items : [
      {
        id : "a",
        attr1 : 0,
        attr2 : 1
      },
      {
        id : "b",
        attr1 : 1,
        attr2 : 2
      }
    ]
  }
}

What is Expected?

The select should use the object with id : "a" as default and allowing to choose among the two options. but keeping the value of objectValue in data consistent with the structure of the object.

What is actually happening?

The select box does not set the object with id : "a" as default and, instead, the placeholder text is displayed.

Most helpful comment

da jia neng bu neng bu yong english jie da wo kan bu dong a

All 8 comments

you can do this example

@Bishop92 Try the above example. Make sure objectValue and one of the items are referring to the same object.

but sometimes I didn't know the index which the default data in a remote array

you can fetch data at first,then find the index in the remote array
example

These two examples are not working anymore in the latest version(1.4.2), so that maybe a bug?

@troy351 update the demo
in new version , you should add value-key
see the pr https://github.com/ElemeFE/element/pull/5897

@PanJiaChen thanks a lot

da jia neng bu neng bu yong english jie da wo kan bu dong a

Was this page helpful?
0 / 5 - 0 ratings