KodeKreachor
KodeKreachor

Reputation: 8882

Traverse knockout to root from outside view model hierarchy scope

If I'm outside the context of a knockout object hierarchy (like in a globally referenced common class), is it possible to

  1. determine if an overall root view model exists (in other words, determine if applyBindings was called for the current view)?
  2. if it exists, locate the overall root view model of the view I'm currently on?

Does anyone know of any utils or extensions that do this?

Upvotes: 1

Views: 1345

Answers (1)

RP Niemeyer
RP Niemeyer

Reputation: 114792

You will want to look at using ko.dataFor and/or ko.contextFor, as described here: http://knockoutjs.com/documentation/unobtrusive-event-handling.html

Given an element, they will tell you the data or context ($data, $root, $parent, $parents) that would be available for binding at that level.

Upvotes: 2

Related Questions