0
ractive.js 루프 내에 여러 질문이 생성되었습니다. 각 질문마다 가격이 다른 여러 답변이 있습니다. 선택한 가격이 변경 될 때마다 총 가격을 계산하고 다시 계산해야합니다. 이 도움이 필요합니다. http://codepen.io/Nitoiti/pen/GjxXvoractive를 사용하여 여러 라디오의 총 가치를 계산하는 방법
<h1>Get total price</h1>
<div id='container'></div>
<script id='template' type='text/ractive'>
{{#each designQuestions}}
<p><span>{{id}} </span> {{question}}</p>
{{#each answers}}
<label><input type='radio' name='designQuestions-answers-{{id}}' value='{{price}}' {{#if selected}} checked {{/if}} >{{answer}} - {{price}}</label>
{{/each}}
{{/each}}
<table class="total">
<tr>
<td>total price:</td>
<td>{{total}}</td> <!-- how to calculate total price and change it on radio buttons change? -->
</tr>
</table>
</script>
<script src='http://cdn.ractivejs.org/latest/ractive.min.js'></script>
<script>
var ractive, designQuestions;
designQuestions = [
{ id: '1',
question: 'Question1 ?',
answers: [
{answer:'answer1',price:'222', selected: 'selected'},
{answer:'answer2',price:'553'},
{answer:'answer3',price:'22'},
{answer:'answer4',price:'442'}
]
},
{ id: '2',
question: 'Question2 ?',
answers: [
{answer:'answer1',price:'22'},
{answer:'answer2',price:'55', selected: 'selected'},
{answer:'answer3',price:'0'},
{answer:'answer4',price:'44'}
]
}
];
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',
// Here, we're passing in some initial data
data: {
designQuestions: designQuestions
}
});
</script>