Node.js Express应用程序中的Jade(1.0+)模板错误:'不允许'重复密钥“id”。

时间:2014-01-02 23:53:45

标签: javascript node.js templates express pug

感谢您对此提出的任何建议:

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

Duplicate key "id" is not allowed.

(从我可以收集的内容来看,我没有将任何带有索引“id”的参数传递给模板)

该应用程序适用于Jade 0.32.0,但打破任何版本1.0 +。

这是我构造参数数组的代码(函数:setJadeVars,第29行),然后将该数组传递给jade模板(第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!' ] ]
}

任何关于可能导致错误的想法都将深表感谢!谢谢!

1 个答案:

答案 0 :(得分:2)

此错误是由以下代码引起的:

span#foo#bar

或者这个:

span#foo(id='bar')

注意两个id标记。我最近也遇到过这个。如果你找不到它,请显示有问题的玉石模板,我可以指出它。