[英]Displaying an array Meteor Helper
For each question I'm trying to display the choices array in an li using Meteor Helpers. 对于每个问题,我正在尝试使用Meteor Helpers在li中显示choices数组。
MongoDB my collection is: MongoDB我的收藏是:
{ "_id" : "AS7zMpdqWzpRyzdDw", "question" : "Favorite Color?", "answer" : "Blue", "choices" : [ "Blue", "Green", "Red", "Black" ] }
{ "_id" : "RaDxyRjDyL4at6oN4", "question" : "Favorite Truck?", "answer" : "Ram", "choices" : [ "Silverado", "Tundra", "Ram", "Titan" ] }
{ "_id" : "n6kvXfoLKueTZiR2A", "question" : "Favorite Animal?", "answer" : "Dog", "choices" : [ "Cat", "Dog", "Horse", "Fish" ] }
code for the helper is 助手的代码是
Template.genKnow.helpers({
question(){
return GenKnow.find({});
},
}); });
code for the html is html的代码是
{{#each question}}
<div id="testQuestions">
<div class="question" id="question">
<h3 id="quesNum">QUESTION</h3>
<p id="questions">{{question}}</p>
</div>
<div class="choices">
<h3>CHOICES</h3>
<ol id="choices">
<li>{{choices}}</li>
</ol>
</div>
<div class="answer">
<h3>CORRECT ANSWER</h3>
<p id="answer">{{answer}}</p>
</div>
</div>
{{/each}}
screen shot of what it is returning 返回的屏幕截图
For choices it is returning 对于选择,它正在回归
1. Blue, Green, Red, Black
I want it to return 我要它回来
1. Blue
2. Green
3. Red
4. Black
I tried 我试过了
<div class="choices">
<h3>CHOICES</h3>
<ol id="choices">
{{#each {{choices}} }}
<li></li>
{{/each}}
</ol>
</div>
got error message 收到错误消息
<div class="choices">
<h3>CHOICES</h3>
<ol id="choices">
{{#each question.choices }}
<li></li>
{{/each}}
</ol>
</div>
still error 仍然错误
Any idea how to get the array to return as a li item? 任何想法如何使数组作为li项返回?
Thank you 谢谢
I used a meteor methods to perform the query where you have return GenKnow.find ({}); 我使用流星方法在返回GenKnow.find({})的位置执行查询。 I would query using a 我会使用查询
Template.genKnow.helpers({
question(){
Meteor.call('meteorMethod', dataObject, function(error, success) {
if (error) {
console.log('error', error);
}
if (success) {
for (var i = 0; i < success.length; i++) {
var element = success[i];
return element
}
}
});
},
Then there in my method 然后在我的方法中
Meteor.methods({
meteorMethod: function() {
Return GenKnow.find ({this.userId}) fetch ();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.