-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
popup-picker动态添加选项失败 #189
Comments
Reset and render the scroller may be helpful |
@VinceXie 收到,我去检查一下 |
@airyland 还是有bug。 value2name.js:line 11 Uncaught TypeError: Cannot read property 'name' of undefined 原因:因为value经过初始化后已经被赋值为一个default值,然后data指向新数组或移除default值的话,value的值便找不到data所对应的数据而出错 解决方法:data每次改动后,value重新遍历data看能否找到对应数据,找不到的话重新赋予一个default值。 希望尽快修复。谢谢。 |
@VinceXie 你是拉取代码测试的吗?给个重现demo |
我在自己的项目上测试的。 你在https://github.com/airyland/vux/blob/master/src/demos/Popup-picker.vue 的组件里添加如下代码应该可以复现: ready () {
this.list3 = [{
name: 'a',
value: 'a',
parent: 0
}, {
name: 'b',
value: 'b',
parent: 0
}, {
name: 'c',
value: 'c',
parent: 'a'
}, {
name: 'd',
value: 'd',
parent: 'b'
}]
} 对data数组重新赋值value就找不到数据而崩了。 |
你确定你拉取了开发代码测试?这个版本还没发布。 |
我拉取的是0.0.117,那我拉取最新的开发代码测试一下吧。 |
等下我发个dev版本的npm包你再试下,我以为你clone了代码测试。 |
不过我picker的代码是手动同步到最新的 |
好 发了dev版本跟我说一声。 |
@airyland 我拉取了master中sha1为e33b17682f7806aaa285ab207a4597bf10244a61的最新版本添加如上代码,bug依然复现。 <template>
<div>
<group title="single column">
<popup-picker :title="title1" :data="list1" :value.sync="value1"></popup-picker>
</group>
<br>
<div class="picker-buttons">
<x-button type="primary" @click="changeList10">重新赋值列表</x-button>
<x-button type="primary" @click="changeList11">push方式更改列表</x-button>
</div>
<group title="double columns">
<popup-picker :title="title2" :data="list2" :value.sync="value2"></popup-picker>
</group>
<br>
<group title="chained columns">
<popup-picker :title="title3" :data="list3" :columns="3" :value.sync="value3"></popup-picker>
<popup-picker :title="title4" :data="list3" :columns="3" :value.sync="value4" show-name></popup-picker>
</group>
<br>
<div class="picker-buttons">
<x-button type="primary" @click="changeList21">push方式更改列表</x-button>
</div>
</div>
</template>
<script>
import { PopupPicker, Group, Picker, XButton } from '../components'
export default {
ready () {
// console.log(this.list3)
this.list3 = [{
name: 'a',
value: 'a',
parent: 0
}, {
name: 'b',
value: 'b',
parent: 0
}, {
name: 'c',
value: 'c',
parent: 'a'
}, {
name: 'd',
value: 'd',
parent: 'b'
}]
},
components: {
PopupPicker,
Group,
Picker,
XButton
},
methods: {
changeList10 () {
this.list1 = [['小米1', 'iPhone1', '华为1', '情怀1', '三星1', '其他1', '不告诉你1']]
},
changeList11 () {
this.list1[0].push('我是push条目')
},
changeList20 () {
},
changeList21 () {
this.list3.push({
name: '美国002_007',
value: '0007',
parent: 'usa002'
})
}
},
data () {
return {
title1: '手机机型',
title2: '详细机型',
title3: '联动显示值',
title4: '联动显示文字',
list1: [['小米', 'iPhone', '华为', '情怀', '三星', '其他', '不告诉你']],
list2: [['小米', 'iPhone', '华为', '情怀', '三星', '其他', '不告诉你'], ['小米1', 'iPhone2', '华为3', '情怀4', '三星5', '其他6', '不告诉你7']],
list3: [{
name: '中国',
value: 'china',
parent: 0
}, {
name: '美国',
value: 'USA',
parent: 0
}, {
name: '广东',
value: 'china001',
parent: 'china'
}, {
name: '广西',
value: 'china002',
parent: 'china'
}, {
name: '美国001',
value: 'usa001',
parent: 'USA'
}, {
name: '美国002',
value: 'usa002',
parent: 'USA'
}, {
name: '广州',
value: 'gz',
parent: 'china001'
}, {
name: '深圳',
value: 'sz',
parent: 'china001'
}, {
name: '广西001',
value: 'gx001',
parent: 'china002'
}, {
name: '广西002',
value: 'gx002',
parent: 'china002'
}, {
name: '美国001_001',
value: '0003',
parent: 'usa001'
}, {
name: '美国001_002',
value: '0004',
parent: 'usa001'
}, {
name: '美国002_001',
value: '0005',
parent: 'usa002'
}, {
name: '美国002_002',
value: '0006',
parent: 'usa002'
}],
value1: ['iPhone'],
value2: ['iPhone', '华为3'],
value3: [],
value4: []
}
}
}
</script>
<style scoped>
.picker-buttons {
margin: 0 15px;
}
</style> |
看起来不是Picker底层的问题了,是popup picker 转换key和value出现的问题。一时没时间处理,有空可以发个PR。 |
而且取消好像有问题,取消之后,值还是改变了。 |
@transtone 已经修复了。等发布吧。 |
@airyland 这个动态赋值的功能什么时候能够解决 Version0.1.2 Android or iOS, which browser?chrome Your Codes组件方法this.list4 = [{ name: 'EE', value: 4, parent: 0 }, 错误提示Cannot read property 'name' of undefined |
@liu7923032 list4默认值是什么? |
list4: [{ name: 'AA', value: 0, parent: 0 }, |
默认value是什么 |
@airyland 默认是空数组 [] |
@airyland 在我这边的系统设计中,一般都是key/value类型的数据,我目前解决的方法是通过popup/selector来展示选项,但是我感觉popup-picker更加友好,但是目前popup-picker对 key/value支持不是特别友好 |
引用picker组件, |
@kevinlvhsl 我也遇到这个问题 |
@Baiang 必须赋初始选中值。 感觉应该修复一下这个问题, 没有初始选中值的时候,默认用第一项 |
这个组件的文档貌似没有只能看 demo。 |
I think I did fix it, finally.. |
我这样解决,有点ugly: ) export default function (value, list, delimiter) { |
Version
0.0.117
Android or iOS, which browser?
chrome
Your Codes
Expected behavior and actual behavior.
打log可以看到列表的数据是无误的,但显示不出来。
Steps to reproduce the problem
The text was updated successfully, but these errors were encountered: