javascript Knockout renderTemplate() 渲染模式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13252505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 18:12:09  来源:igfitidea点击:

Knockout renderTemplate() rendering modes

javascripttemplatesknockout.jscustom-binding

提问by Brett Postin

I'm trying to call ko.renderTemplate()in a custom binding.

我正在尝试调用ko.renderTemplate()自定义绑定。

However I can't find any documentation for it's usage, particularly the rendering mode parameter.

但是我找不到任何关于它的用法的文档,特别是渲染模式参数。

Knockout.js pro tips – working with templates

Knockout.js 专业提示——使用模板

The site above has a section "You can render templates directly from your custom bindings"that briefly describes the parameters to renderTemplate().

上面的站点有一个部分“您可以直接从自定义绑定呈现模板”,其中简要描述了renderTemplate().

What are the other available options for the rendering mode parameter?

渲染模式参数还有哪些其他可用选项?

Additionally, is there any documentation for renderTemplate()and the rendering engine options that I may have missed?

此外,是否有任何文档renderTemplate()和我可能错过的渲染引擎选项?

回答by gregpakes

Just from looking at the source code of 2.2.0.

仅从查看2.2.0的源代码。

The renderMode parameter seems to have two options:

renderMode 参数似乎有两个选项:

  • replaceNode- This will replace the entire target node with the output of the template.
  • replaceChildren- Default. This will replace only the children of the target node, leaving the target node intact.
  • replaceNode- 这将用模板的输出替换整个目标节点。
  • replaceChildren-默认。这将仅替换目标节点的子节点,而保持目标节点完好无损。

回答by ADi3ek

You can find ko.renderTemplate() explained pretty well with some examples in this article.

您可以发现 ko.renderTemplate() 在本文中通过一些示例进行了很好的解释。