Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select does not support default object value #2479

Closed
Bishop92 opened this issue Jan 17, 2017 · 8 comments
Closed

Select does not support default object value #2479

Bishop92 opened this issue Jan 17, 2017 · 8 comments

Comments

@Bishop92
Copy link

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.

@PanJiaChen
Copy link
Contributor

you can do this example

@Leopoldthecoder
Copy link
Contributor

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

@lichinlichin
Copy link

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

@PanJiaChen
Copy link
Contributor

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

@troy351
Copy link
Contributor

troy351 commented Aug 18, 2017

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

@PanJiaChen
Copy link
Contributor

PanJiaChen commented Aug 18, 2017

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

@troy351
Copy link
Contributor

troy351 commented Aug 18, 2017

@PanJiaChen thanks a lot

@cookiexyx
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants