I've seen a few Dart examples/tutorials that look like <template iterate="thing in collection">
and others that use <template repeat="thing in collection">
. They seem to do exactly the same thing. What's the difference between them and why is one recommended instead of the other in a given situation?
dart - 之间的区别 and
I've seen a few Dart examples/tutorials that look like <template iterate="thing in collection">
and others that use <template repeat="thing in collecti
问问题
234 次
Very new to Javascript. How can I make this code extendable/cleaner?
For a webapp that I am developing I need to populate table columns with data that changes dependent on a dropdown select menu. I have a solution below, which works fine and all, but as I only really started learning javascript/JQuery this morning I am sure it isn't a very good one. When I start to work with larger tables or with lots of dropdown fields it's going to get messy. Is there any way I can do this better?
Thanks,
Mark
var GBP = new Array();
GBP[0] = "£1";
GBP[1] = "£2";
GBP[2] = "£3";
GBP[3] = "£4";
GBP[4] = "£5";
GBP[5] = "£6";
GBP[6] = "£7";
var EUR = new Array();
EUR[0] = "€1";
EUR[1] = "€2";
EUR[2] = "€3";
EUR[3] = "€4";
EUR[4] = "€5";
EUR[5] = "€6";
EUR[6] = "€7";
var USD = new Array();
USD[0] = "$1";
USD[1] = "$2";
USD[2] = "$3";
USD[3] = "$4";
USD[4] = "$5";
USD[5] = "$6";
USD[6] = "$7";
$(document).ready(function() {
//populate currency column with default values (GBP)
$('#prices tr').each(function(i) {
$(this).find('.currency').html(GBP[i]);
});
//populate the currency column with a value dependent
//on the selector dropdown
$('.currency-select').change(function() {
if($(this).val() == "GBP"){
$('#prices tr').each(function(i) {
$(this).find('.currency').html(GBP[i]);
});
}
if($(this).val() == "EUR"){
$('#prices tr').each(function(i) {
$(this).find('.currency').html(EUR[i]);
});
}
if($(this).val() == "USD"){
$('#prices tr').each(function(i) {
$(this).find('.currency').html(USD[i]);
});
}
});
});
4
1 回答
10
这里直接来自更新日志:
添加了“模板重复”,与模板迭代不同,如果用作属性,它会重复标签而不是标签的子标签。
原因是以下 HTML 对大多数 HTML 解析器无效:
<select>
<template iterate='name in results'>
<option>{{name}}</option>
</template>
</select>`
template
标签内不允许使用select
,因此解决方案是使用:
<select>
<option template repeat='name in results'>{{name}}</option>
</select>
template repeat
最近添加(2013 年 4 月),它将template iterate
最终取代 AFAIK,但目前两者都受支持。
于 2013-05-25T22:37:11.383 回答
I've seen a few Dart examples/tutorials that look like <template iterate="thing in collection">
and others that use <template repeat="thing in collecti
Very new to Javascript. How can I make this code extendable/cleaner?
For a webapp that I am developing I need to populate table columns with data that changes dependent on a dropdown select menu. I have a solution below, which works fine and all, but as I only really started learning javascript/JQuery this morning I am sure it isn't a very good one. When I start to work with larger tables or with lots of dropdown fields it's going to get messy. Is there any way I can do this better?
Thanks,
Mark
var GBP = new Array();
GBP[0] = "£1";
GBP[1] = "£2";
GBP[2] = "£3";
GBP[3] = "£4";
GBP[4] = "£5";
GBP[5] = "£6";
GBP[6] = "£7";
var EUR = new Array();
EUR[0] = "€1";
EUR[1] = "€2";
EUR[2] = "€3";
EUR[3] = "€4";
EUR[4] = "€5";
EUR[5] = "€6";
EUR[6] = "€7";
var USD = new Array();
USD[0] = "$1";
USD[1] = "$2";
USD[2] = "$3";
USD[3] = "$4";
USD[4] = "$5";
USD[5] = "$6";
USD[6] = "$7";
$(document).ready(function() {
//populate currency column with default values (GBP)
$('#prices tr').each(function(i) {
$(this).find('.currency').html(GBP[i]);
});
//populate the currency column with a value dependent
//on the selector dropdown
$('.currency-select').change(function() {
if($(this).val() == "GBP"){
$('#prices tr').each(function(i) {
$(this).find('.currency').html(GBP[i]);
});
}
if($(this).val() == "EUR"){
$('#prices tr').each(function(i) {
$(this).find('.currency').html(EUR[i]);
});
}
if($(this).val() == "USD"){
$('#prices tr').each(function(i) {
$(this).find('.currency').html(USD[i]);
});
}
});
});
1 回答
这里直接来自更新日志:
添加了“模板重复”,与模板迭代不同,如果用作属性,它会重复标签而不是标签的子标签。
原因是以下 HTML 对大多数 HTML 解析器无效:
<select>
<template iterate='name in results'>
<option>{{name}}</option>
</template>
</select>`
template
标签内不允许使用select
,因此解决方案是使用:
<select>
<option template repeat='name in results'>{{name}}</option>
</select>
template repeat
最近添加(2013 年 4 月),它将template iterate
最终取代 AFAIK,但目前两者都受支持。