如何防止在执行敲除绑定之前显示HTML

如何防止在执行敲除绑定之前显示HTML

本文介绍了如何防止在执行敲除绑定之前显示HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在HTML中使用以下敲除脚本:

I am using the following knockout scripts in my Html:

<!-- kno ifnot: bla -->

 <tr><td>some stuff</td></tr>

<!-- /ko -->

我遇到的问题是,在执行绑定之前,该行将显示一两秒钟.

The problem I have is that before the bindings are executed this row will show for a second or two.

如何防止这种情况发生?

How can I prevent this from happening?

推荐答案

这是一个简单的技巧.只需将您的根元素初始隐藏,然后将可见绑定设置为true.

Here's a simple trick. Just make your root element initially hidden and set the visible binding to true.

<div style="display: none;" data-bind="visible: true">
    <!-- the rest of your stuff -->
</div>

渲染后,在剔除之前,它会被隐藏.应用绑定后,挖空将覆盖样式并使其可见.

As it's rendered, before knockout does its thing, it will be initially hidden. When the bindings are applied, knockout will override the style and make it visible.

或者,您可以将视图放入脚本块并通过模板实例化.脚本块不会被渲染,但是当敲除渲染模板时将可见.

Alternatively, you can throw your view into a script block and instantiate it through a template. The script blocks will not be rendered but will be visible when knockout renders the template.

<!-- ko template: 'myView' --><!-- /ko -->
<script id="myView" type="text/html">
    <!-- the rest of your stuff -->
</script>

这篇关于如何防止在执行敲除绑定之前显示HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 22:41