javascript - 来自 json 文件的 Angular ui 网格

标签 javascript angularjs json angular-ui-grid

我正在尝试从两个 json 文件加载一个 ui 网格表中的数据,但只有一个文件中有数据。

我为这两个 json 文件准备了两个数组。

$scope.sourceOne = [];
$scope.sourceTwo = [];

然后我使用 $http 服务加载数据

$http.get('SourceOne.json').success(function (data) {
    data.forEach( function( row, index ) {
        $scope.sourceOne.push(data);
    });
    $scope.gridOptions.data = data;
    console.log('data from SourceOne.json', data);
});

$http.get('SourceTwo.json').success(function (data) {
    data.forEach( function( row, index ) {
        $scope.sourceTwo.push(data);
    });
    $scope.gridOptions.data = data;
    console.log('data from SourceTwo.json', data);
});

并且我尝试连接这两个数组并在网格中显示结果。

$scope.myConcatenatedData = $scope.sourceOne.concat($scope.sourceTwo);

请查看plunker

最佳答案

首先,forEach 循环中存在错误(row 作为循环内的数据项):

data.forEach( function( row, index ) {
    $scope.sourceOne.push(row);
});

然后您必须确保第二个数据组在第一个数据组之后加载。

此外,两个数据集的串联必须在加载第二组之后,在成功处理程序内进行。

检查我编辑过的 Plunker:https://plnkr.co/edit/tZ1kPgNGiceTfWcrQm2y?p=preview

关于javascript - 来自 json 文件的 Angular ui 网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35605087/

相关文章:

javascript - 从数组javascript进行条件序列验证

javascript - 在 jQuery 中替换小数

javascript - 在 d3 中链接转换的正确方法是什么?

javascript - 如何在angularjs中的选择选项中使用多选将json数据显示为optgroup

java - 如何在 Dropwizard 1.0.2 中使用 LoggingFeature 打印服务器响应?

ajax - 使用 jQuery 解析 JSON 响应

javascript - 使用 jQuery 或 JS 增加元素宽度

javascript - ExpressJs 中间件导入后不工作

javascript - 从日期时间转换为时间并将其绑定(bind)到 Angular 时间选择器?

javascript - Angular 指令更新父 Controller 对象