【问题标题】:Jade (1.0+) template error in Node.js Express app: 'Duplicate key "id" is not allowed.'Node.js Express 应用程序中的 Jade (1.0+) 模板错误:“不允许重复键“id”。”
【发布时间】:2014-01-20 13:29:43
【问题描述】:

感谢您对此的任何建议:

在我的Express app 中,我将几个参数传递给 Jade 模板,这会产生这个致命错误:

Duplicate key "id" is not allowed.

(据我所知,我没有将任何带有索引“id”的参数传递到模板中)

该应用在 Jade 0.32.0 上运行良好,但在任何 1.0+ 版本上都无法使用。

这是我构造参数数组的代码(函数:setJadeVars,第 29 行),然后将该数组传递给玉模板(第 63 行):

https://github.com/rfcx/rfcx-api-express/blob/master/routes/index.js

该错误似乎与将参数传递到模板中无关,因为该错误仅在我尝试使用参数时发生(即,如果我将参数传入,但不要在任何地方调用它们,渲染发生得很好)。

如果有帮助,这里是我传递给模板的对象的 console.log 转储:

{ current_page: 
   [ 'about',
     'About',
     '/about',
     'Rainforest Connection | About',
     true,
     false ],
  app_version: '832292378e7a',
  node_env: 'development',
  title: 'Title (development)',
  segment_io_client_id: 'wimr8bjvcr',
  addthis_pubid: 'ra-xxx',
  bootstrap_cdn: '/vendor',
  googlelibs_cdn: '/vendor',
  videojs_cdn: '/vendor/video.js',
  cdnjs_cdn: '/vendor',
  rfcx_cdn: '/cdn',
  rfcx_vendor_cdn: '/vendor',
  rfcx_static_cdn: '//x-static.s3.amazonaws.com',
  nav_items: 
   [ [ 'intro',
       'Home',
       '/',
       'Rainforest Connection | Protecting rainforests with real-time data',
       true,
       false ],
     [ 'about',
       'About',
       '/about',
       'Rainforest Connection | About',
       true,
       false ],
     [ 'get_involved',
       'Get Involved',
       '/get_involved',
       'Rainforest Connection | Get Involved',
       true,
       false ],
     [ 'blog',
       'Blog',
       '/blog',
       'Rainforest Connection | Blog',
       false,
       false ],
     [ 'team',
       'Team',
       '/team',
       'Rainforest Connection | Team',
       false,
       false ],
     [ 'tumblr',
       'Tumblr',
       'http://tumblr.rfcx.org/',
       'Rainforest Connection | ',
       true,
       false ],
     [ 'video',
       null,
       '/video',
       'Rainforest Connection | Rainforest Connection | Protecting rainforests with real-time data',
       false,
       true,
       {} ] ],
  social_media: 
   [ [ 'github',
       '[link redacted for stack-overflow]',
       'github-square',
       'Fork our repos on Github!' ],
     [ 'instagram',
       '[link redacted for stack-overflow]',
       'instagram',
       'Check us out on Instagram!' ],
     [ 'flickr',
       'http://flickr.com/photos/rainforestcx/',
       'flickr',
       'Check us out on Flickr!' ],
     [ 'linkedin',
       '[link redacted for stack-overflow]',
       'linkedin-square',
       'Check us out on LinkedIn!' ],
     [ 'google-plus',
       '[link redacted for stack-overflow]',
       'google-plus-square',
       'Check us out on Google+!' ],
     [ 'twitter',
       '[link redacted for stack-overflow]',
       'twitter-square',
       'Check us out on Twitter!' ],
     [ 'facebook',
       '[link redacted for stack-overflow]',
       'facebook-square',
       'Check us out on Facebook!' ] ]
}

任何关于可能导致错误的想法都将不胜感激!谢谢!

【问题讨论】:

  • 你能不能提供一个 .jade 模板来破坏它?
  • 我认为,这不是该对象的问题,您会看到一个带有 ID 的对象键,它将保存最新的id 值,而不是没有,也可以发布该行jade res.render 在哪里被调用?

标签: javascript node.js templates express pug


【解决方案1】:

这个错误是由这样的代码引起的:

span#foo#bar

或者这个:

span#foo(id='bar')

注意两个 id 标签。我最近也遇到这个。找不到的话,把冒犯的玉模拿出来,我可以指点一下。

【讨论】:

  • 我是原始问题的发帖人。这个答案解决了这个问题。感谢您的简洁回答!太棒了!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-04-17
  • 1970-01-01
  • 1970-01-01
  • 2016-04-02
  • 2013-03-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多