javascript - 从 Angular 范围内的数组获取所有对象

标签 javascript jquery arrays angularjs scope

我正在尝试从 Angular 范围内获取数组内的所有对象。我正在使用 jQuery 来获取数组,但我不确定如何从数组中获取每个对象,而不必像 [0] 那样定义它。

angular.element("#scopes").scope().fixtures;

这给了我:

数组[380]

然后我可以从中选择,但我需要一次性将它们全部获取。

谢谢。

最佳答案

编辑:这就是我实现此解决方案的方式。请注意,它不再使用任何 jQuery。它从 API 检索数据,然后迭代数组中的每个项目,以便您可以使用它执行您想要的操作。 angular.forEach Docs

// In your angular controller...
$http({
    url: "myApiUrl",
    method: "GET",
    cache: false,
    params: {
        //whatever API params you want to pass
    }
}).then(function successCallback(response) {
    $scope.fixtures = response.data;
    $scope.fixtures.forEach(function (element, index) {
        // do what you want - as per your comments...
        console.log("Element: " + index);
        console.log("Status: " + element.status);
        console.log("________________________________");
    });

}, function failureCallback() {
    alert("There was an error retrieving the data!");
});

关于javascript - 从 Angular 范围内的数组获取所有对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36730879/

相关文章:

javascript - 从外部txt文件加载图像信息并在html文件中显示

Javascript动态答案文本框

javascript - 函数式 JavaScript : how to implement Function. prototype.not

javascript - 使用 JQuery 阻止重定向 - 我做错了什么?

c - C 编程简介 - [期末考试示例] 回文函数

c - 如何增加指向具有可变长度数组的结构的指针?

javascript - 如何在React中使用 'THIS'的2个不同值

jquery - 如何使用jquery查找和替换某些内容?

javascript - Jquery 模态弹出对话框未加载内容

python - 将一维字节数组转换为二维 numpy 数组的最快方法