我一直試圖通過使用select
標記獲取貨幣兌換更新並使用JQuery獲取值。流星貨幣交換
我原來的計劃是使用來自流星把手的{{#if}}
來做邏輯。在使用MongoDB切換字段時,當用戶點擊不同的選項時,它會自動切換貨幣字段。
我目前正在使用名爲theara:moneyjs
的流星包。請點擊here瞭解包裝信息。
這裏是我當前的代碼,我有:
HTML
<template name="product_table">
<table>
<thead>
<tr>
<th>Product Name</th>
<th>Currency
<select id="currency">
<option value="aud">AUS Dollar</option>
<option value="usd">US Dollar</option>
<option value="hkd">HK Dollar</option>
</select>
{{#each product}}
<tbody>
<tr>
<td>{{productName}}</td>
<td>{{productPrice}}</td>
<!-- {{#if getEXR}} Does not work, since is not a boolean value
<td>{{productPrice}}</td>
{{/if}} -->
</tr>
</tbody>
{{/each}}
</table>
</template>
的JavaScript
Template.product_table.helpers({
product: function() {
return Products.find({}, {sort:{createdAt:-1}});
},
getEXR: function() {
$(document).on('change', '#currency', function() {
var getCurrency = $("#currency option:selected").val();
if (getCurrency === "aud") {
//I am not quite sure, how grab specific field values from MongoDB
fx.convert(Products.find().productPrice()).from("USD").to("AUD");
}
else if (getCurrency === "usd") {
fx.convert(Products.find().productPrice()).from("USD").to("USD");
}
else if (getCurrency === "hkd") {
fx.convert(Products.find().productPrice()).from("USD").to("HKD");
}
}
)};
任何幫助,將不勝感激。
你在發佈你需要的數據嗎?我假設你在客戶端執行此操作時,需要從客戶端數據存儲(minimongo)獲取數據,其次應該使用事件。你做過流星教程的介紹嗎? HTTPS://www.meteor。com/tutorials/blaze/creating-an-app流星在方法上有很大的不同,你將會遇到這樣的困難時刻。 – pushplaybang
對不起,延遲迴復,是的,我正在發佈和訂閱我的數據。我的發佈是在服務器端完成的,而訂閱則在客戶端完成,在同一個JS文件中完成。 –