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

Cascader动态添加数据不显示 #5379

Closed
Biswangluo opened this issue May 16, 2023 · 3 comments
Closed

Cascader动态添加数据不显示 #5379

Biswangluo opened this issue May 16, 2023 · 3 comments

Comments

@Biswangluo
Copy link

重现链接

getArea(id) {
    let that=this
    let params = {
        id: id
    }
    apiJs.getArea(params).then(data => {
        data.forEach(item => {
            item.children = []
            item.id = item.ID.toString()
        });

        if (id != 0) {
            let index = that.data.addressList.findIndex(item => item.ID == id)
            console.log(index)
                this.setData({
                    [`addressList[${index}].children`]:data
                 })
            console.log(this.data.addressList[index])
            console.log(this.data.addressList[index].children)
        } else {
            this.setData({
                addressList:data
             })
             this.setData({
                'addressList[0].children': [],
              })
        }
    })
},

Vant Weapp 版本

1.10.18

描述一下你遇到的问题。

使用官方示例可以正常显示数据 但是切换到动态获取 无法显示数据 已确定数据正常 已经添加进去
微信截图_20230516161119

重现步骤

本地数据没有问题 如果用网络数据 在onChange 回调请求网络 不显示

设备/浏览器

No response

@Biswangluo
Copy link
Author

1.模拟生成地址数据
onLoad里面模拟生成数据
`let _options =[]
_options.push({
"ID": 120000,
"ShortName": "天津",
"children": []
})
_options.push({
"ID": 130000,
"ShortName": "河北",
"children": []
})

this.setData({
    addressList:_options
 })

2.模拟onChange回调塞进去点数据onChange(e) {
const {
value
} = e.detail;
//this.getArea(value)
const children = [
{ ShortName: '杭州市', ID: 330100 },
{ ShortName: '宁波市', ID: 330200 },
];
this.setData({
'addressList[0].children':children
})`

3.结论 经过反复测试 如果在data里面有数据情况下 onChange怎么添加数据都没问题 如果从接口回来的数据 通过setData放进去 onChange 怎么添加都不会显示的 经过模拟 先[]在往里放数据进去 就会失效不知道问题出在何处?
求解答

1 similar comment
@Biswangluo
Copy link
Author

1.模拟生成地址数据
onLoad里面模拟生成数据
`let _options =[]
_options.push({
"ID": 120000,
"ShortName": "天津",
"children": []
})
_options.push({
"ID": 130000,
"ShortName": "河北",
"children": []
})

this.setData({
    addressList:_options
 })

2.模拟onChange回调塞进去点数据onChange(e) {
const {
value
} = e.detail;
//this.getArea(value)
const children = [
{ ShortName: '杭州市', ID: 330100 },
{ ShortName: '宁波市', ID: 330200 },
];
this.setData({
'addressList[0].children':children
})`

3.结论 经过反复测试 如果在data里面有数据情况下 onChange怎么添加数据都没问题 如果从接口回来的数据 通过setData放进去 onChange 怎么添加都不会显示的 经过模拟 先[]在往里放数据进去 就会失效不知道问题出在何处?
求解答

@landluck
Copy link
Contributor

v1.10.19 版本已修复

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

No branches or pull requests

2 participants