javascript - 没有找到数据时, Angular js : value set to 0 for all scopes,

标签 javascript json angularjs

我有默认/硬编码的选择选项(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/

相关文章:

javascript - 如何在 AngularJS/Jasmine 单元测试中模拟图像加载事件?

JavaScript: `new RegExp(' hi' )` versus ` RegExp ('hi' )`?

javascript - Firebase 云函数 - null user.displayName onCreate

javascript -::after 伪元素的垂直对齐

javascript - 如何在 Kendo UI Scheduler 上显示自定义事件?

python - 如何使用 scrapy 将多个页面的数据收集到单个数据结构中

angularjs facebook-login 获取用户数据

Java/JavaScript 日期 : Is this true?

json - 如何使用数组中存储的属性名称修改 javascript 对象

javascript - AngularJS 两个组件之间的过滤器