Handlebars似乎不允许我访问传递给模板的对象内部的数组

问题描述 投票:0回答:1

此问题仅在我将代码迁移到生产中时出现,在我的开发环境中不会发生。

我有一个接收对象的车把模板,例如:

{node: {sections: [{name: 'abc'},{name: 'xyz'}]}}

模板看起来像这样:

{{#each node.sections}}
  {{#ifCond type '==' "image-left-text-right"}}
    {{> admin/section/image-left-text-right}} 
  {{/ifCond}}
  {{#ifCond type '==' "two-columns-image-and-text"}}
    {{> admin/section/two-columns-image-and-text}} 
  {{/ifCond}}
  {{#ifCond type '==' "four-columns"}}
  {{> admin/section/four-columns}} 
  {{/ifCond}}     
{{/each}} 

现在,这一切在我的开发环境中看起来都很好,并且模板可以正确呈现,在生产中什么也没显示。

在控制台记录完我的整个对象后,我可以确认它在那里,并编写了一个小助手来帮助我对其进行控制台记录:

<script>
  console.log('----1---')
  console.log({{{json node}}})
  console.log('----2---')
  console.log({{{json node.sections}}})
  console.log('----3---')
</script>

超级奇怪的是,节点上的console.log返回:enter image description here

但是第二个控制台日志什么也不输出。

就像它无权访问对象上的该属性?

我在开发人员和产品中都运行版本[email protected]。我需要设置的把手中是否存在一些我不知道的奇怪的私有/公共标志,以允许其直接访问数组?

node.js handlebars.js
1个回答
0
投票

所以,显然我错了,我在开发环境中运行4.0.12,在生产环境中运行4.7.6。 package.json文件中的^ 4.0.12导致它安装了较新的版本。显然,此问题与4.7.6有关,现在我将其更改为4.0.12,并将最终调查4.7.6的哪些更改导致了此问题。

© www.soinside.com 2019 - 2024. All rights reserved.