Getting “$item is not defined” on applyBindings

纵饮孤独 提交于 2019-12-04 19:41:04

Ok, looks like I can answer this one myself. The problem seems to be that the part where I did the data-bind and was trying to access the jquery.tmpl variable $item is not actually using jquery.tmpl

<tr data-bind="template: { name: 'itemTemplate', foreach: contentItems, 
        templateOptions:{parentItem: $item} 
        }"> </tr>

That is not inside a template so there is no $item variable to access. $item is associated with jquery.tmpl, not knockoutjs. The way I got around the issue was to just put my view model in there instead.

<tr data-bind="template: { name: 'itemTemplate', foreach: contentItems, 
        templateOptions:{parentItem: viewModel} 
        }"> </tr>

And in the actual templates, (itemTemplate in this example), I can access the $item variable.

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