【问题标题】:how to call a function that return an object with ng-repeat如何使用 ng-repeat 调用返回对象的函数
【发布时间】:2016-10-10 09:19:37
【问题描述】:

我正在尝试使用嵌套的 ng-repeat。但是,上部 ng-repeat 中的值 将作为内部 ng-repeat 中的参数传递。我正在尝试创建一个函数 返回一个数组,以便我可以在内部 ng-repeat 中使用它。但它似乎不起作用。 我怎样才能做到这一点? 这是我的html

<table class="table table-condensed" id="paytable" ng-repeat="row in employeeInfo">
    <thead>
        <tr>
            <td class="col-sm-3">Employee Info</td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>{{employeeInfo.name}}</td>
            <td>
                <ul ng-repeat="row in employeeLoans(employeeInfo)">
                    <li></li>
                </ul>

            </td>
        </tr>
    </tbody>

</table>

这是 angularJS

// this 
$http.get('/api/PreviewEmployee').success(function (data)
{
    $scope.employee = data;

    $scope.Allowances = Allowance(data);
});

$scope.Allowance = function (data)
{
    var result = [];
    for(var i = 0 ; i < data.length ; i++)
    {
            result.push(data[i]);                 
    }
    console.log(result)
    return result;
}

    

提前谢谢!!!

【问题讨论】:

  • 请提供样本数据进行测试
  • 我可以通过这个 $scope.employee = data; 看到从服务器获取的数据;这绝对是一个样本
  • 我认为这可以帮助你stackoverflow.com/questions/26399783/…
  • 我之前看过它,但是我如何构造我的控制器来获取内部 ng-repeat 的值。请我需要帮助另外,我没有使用按钮单击来获取页面上的信息加载

标签: javascript jquery angularjs json


【解决方案1】:

我用示例数据创建了代码笔 var x = $scope.employee;

              var keys = Object.keys($scope.employee);

              var result = [];
              for (var i = 0; i < keys.length; i++) {
                result.push(x[keys[i]]);
              }

              $scope.Allowances = result;
              console.log($scope.Allowances);});

Codepen URL -http://codepen.io/nagasai/pen/EyPZjQ 供参考

希望这对你有帮助:)

【讨论】:

  • 问题是我构建控制器的方式我需要帮助来根据这两个依赖请求构建控制器 // 这应该填充外部 NGRepeat $http.get('/api/PreviewEmployee')。成功(函数(数据){ $scope.employee = 数据;}); // 这应该填充内部 NGRepeat $http.get('/api/PreviewAllowance/' + parentEmpID).success(function (data) { $scope.Allowance = data; });
猜你喜欢
  • 2016-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-27
  • 2012-09-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多