【发布时间】:2020-04-10 16:42:54
【问题描述】:
我有一个通过 API 调用创建的数组。 这是我制作这个数组的方法-
var data5 = ko.observableArray(); /*Most important thing to make the data array observable otherwise it will not show the data of the REST API*/
var arrow = [];
function practiceData() {
// var data = [];/**/
$.getJSON("REST API").then(function(dataset) {
$.each(dataset, function(index, value) {
//console.table((dataset));
//console.log(value.change);
data5.push(value); // PUSH THE VALUES INSIDE THE ARRAY.
arrow.push(value.change);
console.log("arrow", arrow);
arrow.forEach(function(value) {
if (value == 0) {
$("#triangle-down-small").hide();
$("#triangle-up-small").hide();
console.log("rgjak")
console.log(value);
// document.getElementById("navTabBar").style.visibility = "none";
} else if (value < 0) {
// $("#triangle-down-small").hide();
$("#triangle-up-small").hide();
console.log("hcdsb")
console.log(value);
}
});
});
});
}
console.log(箭头)-
arrow (1) [0]
arrow (2) [0, 0]
arrow (3) [0, 0, -100]
JSON 响应结构-
[
{
"change": 0,
"count": 6,
"duration": 4,
"prevcount": 6,
"subcategory": "Consultancy"
}
]
对于 if-else 条件,我无法遍历数组,.hide() 函数仅适用于 if 条件,不适用于 else-if。 任何帮助表示赞赏。 提前致谢。
【问题讨论】:
-
任何控制台错误?此外,您分解的 sn-ps 也有些混乱。所有这些逻辑都在同一个地方。例如,第二个 sn-p 是
then()调用的延续吗? -
另外,你的第一个 sn-p 并没有清楚地显示 json 响应结构是什么。
-
@t.niese, 第一个sn-p显示console.log("arrow", arrow)
-
@Taplar,我已经编辑了 sn-ps
-
第一个片段仍然不清楚您的 json 响应是什么。
标签: javascript jquery oracle-jet