【发布时间】:2021-05-09 18:52:16
【问题描述】:
这个 Meteor 代码有 let Vehicles= new Mongo.Collection('vehicles'); 和一个 html <div id='Vehicles',我喜欢使用 <get obj in var named Veh>.find({}).count() 下面的代码工作正常,但我阅读以避免使用 eval()。阅读替代方案并不能满足我对解决方案的正式化。请帮助解决方案或展示如何以非eval() 方式编写此内容。谢谢
更新:它需要在服务器“nodeJs”上运行,而不是在浏览器中
//cliant/main.js
$('input').on('blur', function(e) {
let collectionVar= $(this).parents('div')[2].id // Vehicles is the same as the collection variable.
console.log(eval(collectionVar).find({}).count()) // works but need an alternative to eval()
})
<template name="Vehicles">
<div id="Vehicles" class="subject-container" >
<div class="section-head">
<div class="control">
<input id="plate" type="text" size="6" placeholder="plate" value={{vehicle.plate}}>
</div>
</div>
</div>
</template>
【问题讨论】:
-
sectionId的值类型是什么?能举个例子吗?
-
为了清楚起见,我将“selectionId”更改为“collectionVar”。它的值为“Vehicles”,与集合变量名称相同
标签: javascript meteor