Closed
Description
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.
Activity
PanJiaChen commentedon Jan 18, 2017
you can do this example
Leopoldthecoder commentedon Jan 18, 2017
@Bishop92 Try the above example. Make sure
objectValue
and one of theitems
are referring to the same object.lichinlichin commentedon Feb 21, 2017
but sometimes I didn't know the index which the default data in a remote array
PanJiaChen commentedon Feb 21, 2017
you can fetch data at first,then find the index in the remote array
example
troy351 commentedon Aug 18, 2017
These two examples are not working anymore in the latest version(1.4.2), so that maybe a bug?
PanJiaChen commentedon Aug 18, 2017
@troy351 update the demo
in new version , you should add
value-key
see the pr #5897
troy351 commentedon Aug 18, 2017
@PanJiaChen thanks a lot
cookiexyx commentedon Apr 2, 2018
da jia neng bu neng bu yong english jie da wo kan bu dong a