我想知道如何使动态添加的嵌套对象的淘汰绑定工作。以下示例演示了我的意思,当我单击“初始化内部”按钮时,它不显示“内部值”:
<div data-bind="with: InnerObj">
<div data-bind="text: Pr"></div>
</div>
<button data-bind="click: initInner">Init inner</button>
<script type="text/javascript" language="javascript">
var obj = {
InnerObj: null,
initInner: function () {
this.InnerObj = { Pr: "inner value" };
}
}
$(function () {
ko.applyBindings(ko.mapping.fromJS(obj));
});
</script>