我一直试图在Meteor js中使用lodash.js,并且需要帮助才能做到这一点。我已经尝试了将所有外部文件附加到流星的方法,但仍然是同样的错误。
我想要在模板中使用dropdown with search on codepen。我今天已经参加了8个多小时,但还没弄明白该做什么。此外,当添加外部js文件的URL时,我将此包添加到Meteor并且错误仍然存在。这是我的实施:
<template name="multiselect">
<div class="instructions">(Click to expand and select states to filter)</div>
<div class="dropdown-container" style="width: 100%;">
<div class="dropdown-button noselect">
<div class="dropdown-label">States</div>
<div class="dropdown-quantity">(<span class="quantity">Any</span>)</div>
<i class="fa fa-filter"></i>
</div>
<div class="dropdown-list" style="display: none;">
<input type="search" placeholder="Search states" class="dropdown-search"/>
<ul></ul>
</div>
</div>
</template>
这是我不断得到的错误:
VM31646:100Uncaught ReferenceError: startCase is not defined(anonymous function) @ VM31646:100_.each._.forEach @ underscore.js?hash=cde485f…:149(anonymous function) @ VM31646:99DOMRange._insertNodeWithHooks @ blaze.js?hash=f33d3df…:407Blaze._DOMRange._insertNodeWithHooks @ client.coffee:17DOMRange._insert @ blaze.js?hash=f33d3df…:376DOMRange.attach @ blaze.js?hash=f33d3df…:453Blaze._DOMRange.attach @ client.coffee:57DOMRange._insert @ blaze.js?hash=f33d3df…:371DOMRange.attach @ blaze.js?hash=f33d3df…:453Blaze._DOMRange.attach @ client.coffee:57Blaze.render @ blaze.js?hash=f33d3df…:2373_render @ kadira_blaze-layout.js?hash=dbd1396…:204(anonymous function) @ kadira_blaze-layout.js?hash=dbd1396…:77_.extend.withValue @ meteor.js?hash=27829e9…:1077(anonymous function) @ meteor.js?hash=27829e9…:464(anonymous function) @ meteor.js?hash=27829e9…:1105onGlobalMessage @ meteor.js?hash=27829e9…:401
在Meteor中不使用它可以正常工作。
答案 0 :(得分:1)
我怀疑你的Meteor项目中有underscore
库,它与lodash具有相同的“_
”简写并覆盖它。一种解决方法是使用meteor-lodash包,它允许您调用lodash
这样的函数:
lodash.each(usStates, function(s) {
s.capName = lodash.startCase(s.name.toLowerCase());
$('ul').append(stateTemplate(s));
});
答案 1 :(得分:0)
对于寻求解决此相同问题的任何人,在遵循另一篇文章中的示例后,我遇到了同样的问题。挖掘后,我终于意识到我需要使用“_”。在函数调用之前。 我之前的代码(导致错误)是:
"Client: " startCase(camelCase(ckifdefined(idata.name))) + "<br>"
固定代码:
"Client: " + _.startCase(_.camelCase(ckifdefined(idata.name))) + "<br>"