Incorrect this in select

被刻印的时光 ゝ 提交于 2019-12-02 01:33:00

To get 'this' to reference the view model you can do the following (assuming the flickr.html view has not been changed):

Change the click binding on the thumbnail a tag from

<a href="#" class="thumbnail" data-bind="click:$parent.select">

to

<a href="#" class="thumbnail" data-bind="click: function (item) { $parent.select(item); }">

Because you are then invoking the select method directly on the $parent object (the view model) the view model will be bound to 'this'.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!