【发布时间】:2015-08-28 06:17:45
【问题描述】:
这是我的 HTML
这是一个 ko 组件。页面加载,并按照您的预期加载组件。 visible: binding 设置为 false 开始,并在单击按钮时更改以显示此模式。但是, $root.configurator.thisRow() 或...thisTab() 没有值,并且在按钮单击事件触发之前不能有值,其中 $root.configurator.storeRows(tab,row) 被调用。
如何延迟加载此模板,直到 ...thisRow() 和 ...thisTab() 具有值之后?注意:不能使用jQuery
<div class="config-div">
<div class="my-table">
<div data-bind="text: $root.configurator.thisRow().description.substring(0,5)"></div>
<div data-bind="attr: {id: $root.configurator.thisTab().name.substring(0,4) +'-'+ $root.configurator.thisRow().description.substring(0,5)">
<div data-bind="text: $root.configurator.initConfigSorted(thisTab(), thisRow())"></div>
<!--ko foreach: {data: $root.configurator.config.blah, as: 'thing'}-->
<div class="config-list">
<div class="row single-row list-group-item">
<div class="col-md-6">
<p data-bind="text: thing.name"></p>
</div>
</div>
</div>
<!--/ko-->
</div>
<button data-bind="click: function(){ $root.configurator.toggleConfig() }">Submit</button>
【问题讨论】: