【发布时间】:2014-03-03 08:42:40
【问题描述】:
Ryan N 在couple posts 中使用了一种他称之为“子可观察对象”的技术,他将可观察对象挂在“父”可观察对象上。它看起来像这样:
var parent = ko.observable("I'm the parent");
parent.sub = ko.observable("I'm the child");
parent() //="I'm the parent"
parent.sub() //="I'm the child"
这是一种非常方便的技术,我已经在几个扩展器中使用了它。使用 Knockout ES5 插件,除非您在视图模型上调用 get getObservable(),否则它看起来将无法访问。在绑定中,这看起来很丑陋,但有时您无法访问父对象所附加的对象。
是否有与 ES5 兼容的方法来创建和访问 sub-observables?
【问题讨论】:
-
这是在 Github 上讨论过的:github.com/SteveSanderson/knockout-es5/issues/2
-
看起来这是一个未解决的问题,几个月来没有关于该讨论的任何活动(如 Knockout-ES5 本身)。我现在对采用这个有点担心。
标签: knockout.js knockout-es5-plugin