如何在执行敲除绑定之前防止 Html 显示 [英] How to prevent Html showing before knockout binding is executed

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

问题描述

我在我的 Html 中使用了以下淘汰脚本:

<tr><td>一些东西</td></tr><!--/ko -->

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

如何防止这种情况发生?

解决方案

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

<!-- 你剩下的东西-->

当它被渲染时,在淘汰赛开始之前,它最初会被隐藏.应用绑定后,knockout 将覆盖样式并使其可见.

<小时>

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

<!-- ko 模板:'myView'--><!--/ko --><script id="myView" type="text/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?

解决方案

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 显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆