这种情况将始终 return 'false' 因为类型 'SingleDataSet' 和 'number' 没有重叠 ng2chart [angular]
This condition will always return 'false' since the types 'SingleDataSet' and 'number' have no overlap ng2chart [angular]
大家好我正在尝试检查数组是否包含 0 如果它有 0 那么我想添加 space 代替 0
public atDestinationDoughnutChartData: MultiDataSet = [];
for (let i = 0; i < this.atDestinationDoughnutChartData.length; ++i) {
if (this.atDestinationDoughnutChartData[i] == 0 ) {
this.atDestinationDoughnutChartData.push(this.atDestinationDoughnutChartData[i]);
}}
但是我得到的错误条件总是错误的,如下图所示,请帮我解决这个问题
screenshot
这是一个数据类型不匹配错误。您正在比较类型 MultiDataSet 和类型 number。因此,一个简单的解决方案是将 ! 放在 this.atDestinationDoughnutChartData[i]
之前。 !this.atDestinationDoughnutChartData[i]
等同于 this.atDestinationDoughnutChartData[i] == 0
。
代码:
public atDestinationDoughnutChartData: MultiDataSet = [];
for (let i = 0; i < this.atDestinationDoughnutChartData.length; ++i) {
if (!this.atDestinationDoughnutChartData[i]) { this.atDestinationDoughnutChartData.push(this.atDestinationDoughnutChartData[i]);}}
大家好我正在尝试检查数组是否包含 0 如果它有 0 那么我想添加 space 代替 0
public atDestinationDoughnutChartData: MultiDataSet = [];
for (let i = 0; i < this.atDestinationDoughnutChartData.length; ++i) {
if (this.atDestinationDoughnutChartData[i] == 0 ) {
this.atDestinationDoughnutChartData.push(this.atDestinationDoughnutChartData[i]);
}}
但是我得到的错误条件总是错误的,如下图所示,请帮我解决这个问题
screenshot
这是一个数据类型不匹配错误。您正在比较类型 MultiDataSet 和类型 number。因此,一个简单的解决方案是将 ! 放在 this.atDestinationDoughnutChartData[i]
之前。 !this.atDestinationDoughnutChartData[i]
等同于 this.atDestinationDoughnutChartData[i] == 0
。
代码:
public atDestinationDoughnutChartData: MultiDataSet = [];
for (let i = 0; i < this.atDestinationDoughnutChartData.length; ++i) {
if (!this.atDestinationDoughnutChartData[i]) { this.atDestinationDoughnutChartData.push(this.atDestinationDoughnutChartData[i]);}}