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

accordion异步渲染bug #239

Closed
sitorhy opened this issue Apr 19, 2019 · 0 comments
Closed

accordion异步渲染bug #239

sitorhy opened this issue Apr 19, 2019 · 0 comments

Comments

@sitorhy
Copy link

sitorhy commented Apr 19, 2019

如下代码
wxml

<view>
    <wux-accordion-group>
        <wux-accordion wx:for="{{list}}"
                       wx:key="{{item.id}}"
                       key="{{item.id}}"
                       title="{{item.title}}"
        >
            <view>
                <view class="accordion-content">
                    {{item.content}}
                </view>
            </view>
        </wux-accordion>
    </wux-accordion-group>
</view>

Page.js

Page({
	data:{
		list:[]
	},

	onShow:function()
	{
		setTimeout(()=>{
			this.setData({
				list:[{
					"id":"abc",
					"content":"abc",
					"title":"第一项"
				},{
					"id":"def",
					"content":"def",
					"title":"第二项"
				}]
			});
		},1000);
	}
});

setTimeout模拟请求网络数据
accordion 渲染的列表第一次操作必须点两次才能点开

在不指定key的情况下:

<view>
    <wux-accordion-group>
        <wux-accordion wx:for="{{list}}"
                       wx:key="{{item.id}}"
                       title="{{item.title}}"
        >
            <view>
                <view class="accordion-content">
                    {{item.content}}
                </view>
            </view>
        </wux-accordion>
    </wux-accordion-group>
</view>

点击第二项,展开的却是第一项

目前解决办法是必须指定key,并且需要修改accordion源代码才能工作正常
···
onTap() {
const { index, disabled } = this.data
const parent = this.getRelationNodes('../accordion-group/index')[0]

        if (disabled || !parent) {
            return false
        }

        parent.onClickItem(index)
    }

···
改为
···
onTap() {
const { index, disabled,key } = this.data
const parent = this.getRelationNodes('../accordion-group/index')[0]

        if (disabled || !parent) {
            return false
        }

        parent.onClickItem(key||index);
    }

···

@skyvow skyvow closed this as completed in 8e3c30e Jun 9, 2019
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

1 participant