我想减少NodeJS服务器内存数组的大小。
我只想发送'标题'数组中的每个对象,减少网络流量。我在服务器上有这个数组:
var lotOfThings = [
{name: 'Watson', role: 'Mod', lotOfData: ... },
{name: 'Sherlock', role: 'Admin', lotOfData: ...}
];
我想从lotOfData
中的所有对象中删除lotOfThings
,然后仅向用户发送:
{name: 'Watson', role: 'Mod'},
{name: 'Sherlock', role: 'Admin'}
如何以良好的表现实现这一目标?
答案 0 :(得分:4)
普通JS:
<form method="POST" action="{{ route('postPasswordReset') }}" data-abide novalidate>
{!! csrf_field() !!}
@if (Session::has('status'))
<p>Password Recovery:</p>
<div data-alert class="callout success radius">
<i class="fa fa-thumbs-up fa-lead"></i> {{ Session::get('status') }}
</div>
@else
<p>Please enter your email address to recover password.</p>
<div data-abide-error class="alert callout" style="display: none;">
<p><i class="fi-alert"></i> There are some errors in your form.</p>
</div>
<div class="row">
<div class="small-12 columns">
<label>Email Address
<input type="email" name="email" placeholder="Please enter your email address" required>
</label>
</div>
</div>
<div>
<button class="button small radius expanded success btn-block" type="submit">
Send Password Reset Link
</button>
</div>
@endif
<div>
<a href="{{ route('login') }}">Back to Login Page</a>
</div>
</form>
答案 1 :(得分:3)
使用underscore.js
_.map(lotOfThings,
function(thing) {
return { name: thing.name, role: thing.role };
}
);