简体   繁体   English

从击倒2.3升级到3.2时,嵌套模板失败

[英]Nested templates failed when updating from knockout 2.3 to 3.2

I have a page using knockout 2.3.0 and nested templates that was working fine untill I updated it to version 3.2.0. 我有一个使用敲除2.3.0和嵌套模板的页面,在我将其更新到版本3.2.0之前,它一直运行良好。

If I strip away the rest of the page, the structure that fails looks like this: 如果我剥离页面的其余部分,则失败的结构如下所示:

...
<!-- ko template: {name: 'meta-data-template', foreach: DocumentMetaDataList} -->
<!-- /ko -->
...

<script type="text/html" id="meta-data-template">
  <label data-bind="text: FieldName() + ':', visible: $root.labelIsVisible($data)"></label>
  <!-- ko template: { name: $root.displayAddFieldTemplate, data: $data } -->
  <!-- /ko -->
</script>**

In this case, displayAddFieldTemplate resolves to "meta-add-template" that looks like this 在这种情况下, displayAddFieldTemplate解析为如下所示的"meta-add-template"

<script type="text/html" id="meta-add-template">
  <a class="add-fieldvalue" href="#" data-bind="visible: $root.fieldValueIsVisible($data)">Link</a>
</script>  

I have hardcoded $root.fieldValueIsVisible($data) to return true, so that the link should always be shown. 我已经硬编码了$root.fieldValueIsVisible($data)以返回true,因此应该始终显示该链接。 This however, gives the following javascript error when I run it in the browser: 但是,当我在浏览器中运行它时,会出现以下javascript错误:

Uncaught TypeError: Unable to process binding "template: function (){return { name:$root.displayAddFieldTemplate,data:$data} }"

Message: undefined is not a function 消息:未定义不是函数

If I remove the data-bind from the meta-add-template , so that is looks like this it works as expected. 如果我从meta-add-template删除数据绑定,则看起来像这样,它可以按预期工作。

<script type="text/html" id="meta-add-template">
  <a class="add-fieldvalue" href="#">Link</a>
</script>  

Even if I inline a value into the data-bind it gives the same error message. 即使我将值内联到data-bind它也会给出相同的错误消息。 So it fails for this template as well: 因此,此模板也将失败:

<script type="text/html" id="meta-add-template">
  <a class="add-fieldvalue" data-bind="visible:true" href="#">Link</a>
</script>  

Why does this not work as expected, and why did it stop working after the update from 2.3 to 3.2? 为什么这不能按预期方式工作,为什么从2.3升级到3.2后又停止工作?

Are you using an old version of jquery templates? 您是否正在使用旧版本的jquery模板? That library has been deprecated. 该库已被弃用。 Try removing the reference to that as knockoutjs now has built in support for the same syntax. 尝试删除对它的引用,因为基因敲除js现在已经内置了对相同语法的支持。

jQuery Templates are deprecated? jQuery模板已弃用?

http://knockoutjs.com/documentation/template-binding.html http://knockoutjs.com/documentation/template-binding.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM