Skip to content

Select does not support default object value #2479

Closed
@Bishop92

Description

@Bishop92

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

PanJiaChen commented on Jan 18, 2017

@PanJiaChen
Contributor

you can do this example

Leopoldthecoder

Leopoldthecoder commented on Jan 18, 2017

@Leopoldthecoder
Contributor

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

lichinlichin

lichinlichin commented on Feb 21, 2017

@lichinlichin

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

PanJiaChen

PanJiaChen commented on Feb 21, 2017

@PanJiaChen
Contributor

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

troy351

troy351 commented on Aug 18, 2017

@troy351
Contributor

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

PanJiaChen

PanJiaChen commented on Aug 18, 2017

@PanJiaChen
Contributor

@troy351 update the demo
in new version , you should add value-key
see the pr #5897

troy351

troy351 commented on Aug 18, 2017

@troy351
Contributor

@PanJiaChen thanks a lot

cookiexyx

cookiexyx commented on Apr 2, 2018

@cookiexyx

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Bishop92@PanJiaChen@troy351@Leopoldthecoder@lichinlichin

        Issue actions

          Select does not support default object value · Issue #2479 · ElemeFE/element