我正在尝试从node / express迭代EJS中的JSON数据,当它在第6个引脚上时,将另一个引脚扔进flexbox。
当我尝试以这种方式添加代码时会弹出致命错误(打击)。如何在没有致命错误的情况下实现我的目标?
谢谢!
<% for(i=0; i < articles.length; i++) { %>
<div class="pin" style="margin:1.25rem;">
<a href="/blog/<%- articles[i].slug %>">
<img class="blog-img" src="<%- articles[i].image %>" alt="blog post" style="width:20%;"/>
</a>
<h2><%- articles[i].title %></h2>
<p>
<%- articles[i].summary %>
</p>
<a class="readmore" style="position:relative; margin-top:2rem;" href="/blog/<%- articles[i].slug %>">READ MORE</a>
</div>
<% if( i = 5 ) { %>
<div class="pin" style="margin:1.25rem;">
<img src="images/logo-dark@2x.png" alt="Dome Logo" />
<div class="form-group">
<input onSubmit="submitData()" id="prospect-form" type="email" placeholder="Email Address" class="form-control" style="vertical-align: baseline; display:inline-block; background-color: white; border: none;" />
<button onSubmit="submitData()" id="form-submit" onClick="submitData()" class="btn btn-active" type="submit" style="display: inline-block">Submit</button>
</div>
</div>
<% } %>
<% } %>
错误: &lt; ---最后几个GC ---&gt;
[5347:0x103000000] 37746 ms: Mark-sweep 372.1 (379.5) -> 372.0 (377.5) MB, 1362.6 / 0.0 ms last resort
[5347:0x103000000] 53315 ms: Mark-sweep 906.8 (912.3) -> 548.7 (556.8) MB, 197.0 / 0.4 ms (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 15568 ms) allocation failure GC in old space requested
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x359bac9a66a1 <JS Object>
2: /* anonymous */ [0x3ebc6f402311 <undefined>:~1] [pc=0x5a9ee9bbaad](this=0x1f1e6d598689 <JS Global Object>,locals=0x1606c8d792c9 <an Object with map 0x31a5701d9701>,escape=0x1606c8d62179 <JS Function exports.escapeXML (SharedFunctionInfo 0x1606c8d616b1)>,include=0x1606c8d79281 <JS Function include (SharedFunctionInfo 0x1606c8d737c9)>,rethrow=0x1606c8d79239 <JS Function rethrow (SharedFunc...
FATAL ERROR: invalid array length Allocation failed - JavaScript heap out of memory
1: node::Abort() [/Users//.nvm/versions/node/v7.7.4/bin/node]
2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/Users//.nvm/versions/node/v7.7.4/bin/node]
3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/Users//.nvm/versions/node/v7.7.4/bin/node]
4: v8::internal::Heap::AllocateUninitializedFixedArray(int) [/Users//.nvm/versions/node/v7.7.4/bin/node]
5: v8::internal::Factory::NewUninitializedFixedArray(int) [/Users//.nvm/versions/node/v7.7.4/bin/node]
6: v8::internal::(anonymous namespace)::FastElementsAccessor<v8::internal::(anonymous namespace)::FastPackedObjectElementsAccessor, v8::internal::(anonymous namespace)::ElementsKindTraits<(v8::internal::ElementsKind)2> >::AddArguments(v8::internal::Handle<v8::internal::JSArray>, v8::internal::Handle<v8::internal::FixedArrayBase>, v8::internal::Arguments*, unsigned int, v8::internal::(anonymous namespace)::Where) [/Users//.nvm/versions/node/v7.7.4/bin/node]
7: v8::internal::(anonymous namespace)::DoArrayPush(v8::internal::Isolate*, v8::internal::BuiltinArguments) [/Users//.nvm/versions/node/v7.7.4/bin/node]
8: 0x5a9ee48ed46
编辑:if语句绝对是杀了我的机器。如果我留下那个if节点中的语句使用98%的CPU和1GB的RAM。如果我拿出来它恢复正常。正常是大约60MB的RAM和0%的CPU。
答案 0 :(得分:0)
由于您尝试将值5附加到if条件中的 i ,而不是使用==
比较参数来检查其值,因此您的循环会卡住。
您的if
声明应为
<% if( i == 5 ) { %>