我一直试图通过使用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文件中完成。 –