Meteor'ı, meyvelerin bir listesi ve diğerinin rengine göre iki açılan yeri doldurmak için basit bir örnekle incelemeye çalışıyorum. meyve seçilen:Meteor: açılan menüden seçili bir değerle return ._id ve başka bir aşağı açılana besleme
toplama (productlist):
a = new Array();
a.push({color:"orange"});
a.push({color:"red"});
ProductList.insert({ product: "Orange", a });
a = new Array();
a.push({color:"green"});
a.push({color:"red"});
ProductList.insert({ product: "Apple", a });
a = new Array();
a.push({color:"green"});
a.push({color:"yellow"})
ProductList.insert({ product: "Banana", a });
html (açılır menü):
<template name="prodlist">
<select id="category-select">
<option disabled="disabled" selected="selected">Please Select</option>
{{#each prodlist}}
<option value="{{this}}">{{this}}</option>
{{/each}}
</select>
</template>
js:
Template.prodlist.events({
"change #category-select": function (event, template) {
var category_prod = $(event.currentTarget).val();
//this return the correct element selected in the dropdown(i.e Orange Apple Banana)
console.log("category : " + category_prod);
var productID = ProductList.findOne({product: category_prod })._id
console.log("current ID: " + productID);
}
});
****** ilk sorum
Bu chrisklaussner tarafından çözüldü yukarıda bakınız. Kod güncellendi. ******
Template.colorlist.helpers({
colorlist: function() {
const ans = productID.get();
const product = ProductList.findOne({ _id: ans});
if (product) {
return product.a.map(function (doc) {
return doc.color;
});
}
}
});
bakınız:
html:
<template name="colorlist">
<select id="category-select">
<option disabled="disabled" selected="selected">colors</option>
{{#each colorlist}}
<option value="{{this}}">{{this}}</option>
{{/each}}
</select>
</template>
js
Ayrıca ben İkinci açılır bulunmuştur._id (saved to productID)
beslemeye çalışıyorum Yukarıdaki ikinci soru için
DÜZENLEME: Bu soru çözüldüğünü ve Orijinal Mesaj doğru cevap
Teşekkürler, sadece basında kullanılan ilk parametre ile karıştırıldım. – Alex
Neyi buldum konusundaki soru # 2 için yazıyı düzenledim. Zamanın olduğunda bir bakabilir misin? – Alex
Ne için iade edilmeyi bekliyorsunuz? Bir dizide 'map' '(veya bu durumda Mongo imleci) çağırırsanız, her zaman bir dizi alırsınız. – chrisklaussner