jquery - knockout how to get $parent of $parent -
<div id="root" data-bind="with: $data.building"> <div data-bind="foreach: $data.offices"> <div data-bind="foreach: $data.desks"> <div data-bind="foreach: $data.legs"> <button class="btndestroydeskleg"> destroy</button> </div> </div> </div> </div> <script> $("#root").on('click', '.btndestroydeskleg', function () { var context = ko.contextfor(this), office = ** ? **, desk = context.$parent, leg = context.$data; }); </script>
how can $parent of $parent? in other word, should replace "** ? **" office?
you can use $parents
array described in knockout documentation.
to parent context can use
$parents[0]
to grandparent context can use
$parents[1]
so in case can use
office = context.$parents[1]
Comments
Post a Comment