我有默认/硬编码的选择选项(4 个选项)和 json 数据。 由于我的 json obj 中缺少“SWIZ”数据。当我点击它时,它会给出奇怪的输出。你可以看到 fiddle ... https://jsfiddle.net/tffv2owp/6/由于某种原因,我必须将“SWIZ”选项保留在选择框中。 当我从选择下拉列表中选择“SWIZ”选项时,我需要为所有范围项目设置“0”值。
$scope.months =
[{ "country": "UK", "mon": "JAN", "A": "14", "S": "2"},
{ "country": "AUSTRIA", "mon": "JAN", "A": "24", "S": "12"},
{ "country": "ITALY", "mon": "JAN", "A": "5", "S": "21"},
{ "country": "UK", "mon": "FEB", "A": "4", "S": "12"},
{ "country": "AUSTRIA", "mon": "FEB", "A": "24", "S": "12"},
{ "country": "ITALY", "mon": "FEB", "A": "15", "S": "1"}
];
$scope.countries = ["UK", "AUSTRIA", "ITALY", "SWIZ"];
最佳答案
fork 你的 fiddle
https://jsfiddle.net/g81a10ze/1/
if(fData.length > 0){
this.filteredData = fData;
} else {
this.filteredData = [{ "country": "SWIZ", "mon": "JAN", "A": "0", "S": "0"},
{ "country": "SWIZ", "mon": "FEB", "A": "0", "S": "0"}]
}
关于javascript - 没有找到数据时, Angular js : value set to 0 for all scopes,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31788395/