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

Wepy框架使用通知时this会有问题 #6

Open
SamHz opened this issue Jun 27, 2018 · 1 comment
Open

Wepy框架使用通知时this会有问题 #6

SamHz opened this issue Jun 27, 2018 · 1 comment

Comments

@SamHz
Copy link

SamHz commented Jun 27, 2018

发现你的代码中使用了将page放在observer这样告成回调时this作用域会有问题,变成了{observer, selector, name}这样引用就不对了,而且没办法修改界面,所以我使改了你的代码
原来是这样
var newNotice ={ name: name, selector: selector, observer: observer };
修改后:
var newNotice = Object.assign(observer, {selector: selector}, {name: name}) /* { name: name, selector: selector, observer: observer };*/
合并成一个对像才适用于Wepy

@xztl
Copy link

xztl commented Oct 13, 2018

wepy使用时候,this确实有问题,但是上边处理方法错误,Object.assign会让observer的监听只有一个,新添加监听会覆盖,正确做法是在原来代码上的postNotificationName方法里面的notice.selector(info);代码改为notice.selector.call(notice.observer, info);

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

2 participants