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: use primitive key on tags #5897

Merged
merged 2 commits into from
Jul 20, 2017

Conversation

Leopoldthecoder
Copy link
Contributor

Please make sure these boxes are checked before submitting your PR, thank you!

  • Make sure you follow Element's contributing guide (中文 | English).
  • Make sure you are merging your commits to dev branch.
  • Add some descriptions and refer relative issues for you PR.

#5894

@wacky6
Copy link
Contributor

wacky6 commented Jul 17, 2017

感觉直接用 index 不合适吧?
我觉得让用户自己提供一个生成key的函数比较好。。。

@Leopoldthecoder
Copy link
Contributor Author

@wacky6 不合适是指?

@wacky6
Copy link
Contributor

wacky6 commented Jul 17, 2017

直觉上感觉不太对,item 和 index 不能算一一对应吧,比如:

selected = [A, B] / [B, A]

这两个出来的 key 是一样的。vue文档里建议key是元素的唯一标识。

@Leopoldthecoder
Copy link
Contributor Author

@wacky6 有道理。

现在改成了和 Tree 以及 Table 类似的处理方式,如果 item 是对象的话,要求用户传一个 value-key 进来作为唯一性标识,然后把这个唯一值给 key

以此为契机,修改了判断某个选项是否选中的代码,达到这样一个效果:如果 Select 的绑定值为对象且有初始值,不再要求初始值和 option 中的某个值必须引用同一个对象;而是只要两者 value-key 键的值相同,就认为是被选中的。

@wacky6
Copy link
Contributor

wacky6 commented Jul 18, 2017

LGTM。建议加几个测试用例

@Leopoldthecoder
Copy link
Contributor Author

@wacky6 will do.

@Moerj
Copy link

Moerj commented Aug 3, 2017

@Leopoldthecoder 如果下拉配置项option没有value值, 组件的回显就报错了:
例如多选:

option:[ { id:'01', label:'萝莉' }, { id:'02', label:'御姐' } ]

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

vue报错警告, 多选无法回显选中项
[Vue warn]: children must be keyed:
image

element-ui 1.4.1
vue 2.4.2

@Leopoldthecoder
Copy link
Contributor Author

Leopoldthecoder commented Aug 3, 2017

@Moerj value-key 应该写在 <el-select> 标签上

@Higginshuangjing
Copy link

select的remove-tag不能用吗~ 调用了没有反应 求助

@chikara-chan
Copy link
Contributor

才注意到1.4.0加了value-key, 小伙伴把包升级后,之前好多select组件都挂了,这是个break changing.......

@Leopoldthecoder
Copy link
Contributor Author

@chikara-chan 是啊,changelog 里已经注明是非兼容性更新了。

@1101804766
Copy link

1101804766 commented Jun 7, 2018

如果循环里是一个map呢?value-key又该怎么写?value-key到底是写在select上还是写在option上

@fengyuexingzi
Copy link

value-key到底是写在select上还是写在option上

我也很困惑,文档写value-key,但示例上全是在option上用 :key,你现在理解了没?

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

Successfully merging this pull request may close these issues.

None yet

7 participants