我正试图使用
select
标签和 JQuery 获取值来更新货币兑换。我的原始计划是使用 Meteor handlebars 中的 {{#if}}
来完成逻辑。当用户点击不同选项时,使用 MongoDB 切换字段,它将自动切换货币字段。我目前正在使用一个名为 theara:moneyjs
的 Meteor 包。点击此处获取包信息。以下是我目前的代码:
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");
}
}
)};
非常感谢您的帮助。