[英]Displaying an array Meteor Helper
對於每個問題,我正在嘗試使用Meteor Helpers在li中顯示choices數組。
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" ] }
助手的代碼是
Template.genKnow.helpers({
question(){
return GenKnow.find({});
},
});
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}}
對於選擇,它正在回歸
1. Blue, Green, Red, Black
我要它回來
1. Blue
2. Green
3. Red
4. Black
我試過了
<div class="choices">
<h3>CHOICES</h3>
<ol id="choices">
{{#each {{choices}} }}
<li></li>
{{/each}}
</ol>
</div>
收到錯誤消息
<div class="choices">
<h3>CHOICES</h3>
<ol id="choices">
{{#each question.choices }}
<li></li>
{{/each}}
</ol>
</div>
仍然錯誤
任何想法如何使數組作為li項返回?
謝謝
我使用流星方法在返回GenKnow.find({})的位置執行查詢。 我會使用查詢
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
}
}
});
},
然后在我的方法中
Meteor.methods({
meteorMethod: function() {
Return GenKnow.find ({this.userId}) fetch ();
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.