Using KnockoutJS with detached nodes

前端 未结 3 968
逝去的感伤
逝去的感伤 2020-12-21 05:07

What I\'m looking to do is detach some nodes using jQuery\'s detach method, update my ViewModel, attach my nodes back, and have the values be updated.

Is this possib

3条回答
  •  失恋的感觉
    2020-12-21 06:06

    What happens here is when you call detach method, ko loses bindings to detached nodes. The easiest way to make it work is to re-apply bindings each time you detach and attach nodes.

    See this jsfiddle: http://jsfiddle.net/EZFDt/

    Edit: With that workaround in place, keep in mind there may be performance implications. Perhaps you can re-think the way you approach the problem - can you move nodes to a different, hidden location instead of detaching them? Can you simply hide them?

提交回复
热议问题