如果我在 knockout 对象层次结构的上下文之外(比如在全局引用的公共(public)类中),是否可以
- 确定是否存在整体 Root View 模型(换句话说,确定是否为当前 View 调用了 applyBindings)?
- 如果存在,找到我当前所在 View 的整体 Root View 模型?
有人知道执行此操作的任何实用程序或扩展程序吗?
最佳答案
您将要查看使用 ko.dataFor
和/或 ko.contextFor
,如下所述:http://knockoutjs.com/documentation/unobtrusive-event-handling.html
给定一个元素,它们会告诉您在该级别可用于绑定(bind)的数据或上下文($data、$root、$parent、$parents)。
关于javascript - 从外部 View 模型层次结构范围遍历 knockout 到 root,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10144493/