Cannot set property 'display' of undefined

343 views
Skip to first unread message

greg.d...@gmail.com

unread,
Jul 28, 2011, 12:37:00 PM7/28/11
to knock...@googlegroups.com
I have an issue where I have an afterAdd event firing which hide()'s and then slideDown()'s an item in a knockout template. This works great except for the fact that inside of template I have some code which checks to see if the item is selected.  The code is: 
<script type="text/html" id="sidebarTemplate">
    <li class="sidebar-list-item" data-bind="css: { selected: ($item.selectedId() == _id) }">
        <a href="#" data-bind="text: msg.en_US, click: $item.selectItem"></a>
    </li>
</script>

I get an error in chrome which says: Cannot set property 'display' of undefined

I did some digging and this is because jQuery is trying to hide() <!---->.  When I get rid of the data-bind="css: ..." it all works fine.  I think it has to do with the fact that it takes a bit of time to evaluate that, but I am not sure.

rpn

unread,
Jul 29, 2011, 12:20:41 AM7/29/11
to knock...@googlegroups.com
Hello-
The comment gets added as part of the template processing.  You can work around this by making your afterAdd function look something like: 

function(elements) { $(elements).filter('li').hide().slideDown() } 
Reply all
Reply to author
Forward
0 new messages