Sha*_*der 0 angularjs ng-repeat angularjs-ng-repeat
我是angularjs的新手并且正致力于创建示例应用程序.我正在使用ng-repeat指令.我的控制器看起来像这样:
app.controller('CustomerController',function ($scope) {
$scope.customers = [{ Name: 'Emp One' }, { Age: 10 }, { Salary: 100000000 },
{ Name: 'Emp Two' }, { Age: 20 }, { Salary: 2000000 },
{ Name: 'Emp Three' }, { Age: 30 }, { Salary: 300000000 }];
$scope.AddCustomer = function() {
$scope.customers.push($scope.NewCutomer.Name, $scope.NewCutomer.Age, $scope.NewCutomer.Salary);
};
})
Run Code Online (Sandbox Code Playgroud)
现在在视图中我只是打印输出.
<div ng-repeat="cust in customers">
<p>Name: {{cust.Name}} Age: {{cust.Age}} Salary: {{cust.Salary}}</p>
</div>
Run Code Online (Sandbox Code Playgroud)
看下面的图像,而不是产生3行,系统产生9行.

我希望输出像
Name: EmpOne Age: 10 Salary: 10000000
Name: EmpTwo Age: 30 Salary: 2000000
Name: EmpThree Age: 30 Salary: 300000000
Run Code Online (Sandbox Code Playgroud)
您的对象格式不正确,应该是:
$scope.customers = [{ Name: "Emp One", Age: 10, Salary: 100000000 },
Run Code Online (Sandbox Code Playgroud)
等等.否则,每个对象都会获得一个新行,就像您当前的结果一样.
| 归档时间: |
|
| 查看次数: |
40 次 |
| 最近记录: |