我有一个使用 firebase 的简单测试应用程序,带有以下模板和模型。我想访问计算的 newprice 中的价格值,以将其格式化为具有 2 个小数位的货币。我不知道如何获得在输出中显示良好的 .price 值,但我尝试过的任何东西似乎都无法在计算中看到 .price 。对 newprice 的调用工作正常,因为我可以返回文本并在输出中看到它。它使用 .price 的原因是从 firebase 返回的数据将每个品牌、型号、价格包装在一个唯一的自动生成的 id 中,所以我看到一个顶级对象,每个条目 id 和其中的数据作为具有品牌、型号的对象,价格。
<script id='template' type='text/ractive'>
{{#each listdata:i}}
<p>{{ .make }} {{ .model }}{{.price}} ${{ newprice() }}!</p>
{{/each}}
</script>
<script>
var ractive = new Ractive({
// The `el` option can be a node, an ID, or a CSS selector.
el: 'container',
// We could pass in a string, but for the sake of convenience
// we're passing the ID of the <script> tag above.
template: '#template',
computed: {
newprice: function() {
// CAN'T FIGURE OUT WHAT TO DO HERE TO SEE price
return ;
}
}
});
</script>
需要一些关于如何获得 .price 价值的指导。