次のテンプレートとモデルを ractive で使用して、firebase を使用した簡単なテスト アプリケーションを作成しました。計算された newprice の価格値にアクセスして、小数点以下 2 桁の通貨のように書式設定したいと考えています。出力に問題なく表示される .price 値を取得する方法はわかりませんが、計算された内部で .price を表示できるように試したことはありません。newprice の呼び出しは、テキストを返すだけで出力に表示されるため、正常に機能します。.price を使用している理由は、firebase から返されたデータには、一意の自動生成 ID でラップされた各 make、model、price があるため、各エントリ ID を持つトップ レベル オブジェクトとその中のデータが make、model、価格。
<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 値を取得する方法についての指示が必要です。