Pra*_*nan 2 javascript json angularjs
见下面的代码:
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://www.w3schools.com/angular/customers.php")
.then(function (response) {
$scope.names = response.data.records;
});
});
Run Code Online (Sandbox Code Playgroud)
在上面的示例中,我们编写了用于获取记录中的所有数据的代码存储在名称中,但要求是前5个数据应存储在名称中.
提前致谢
小智 5
有两种方法可以做到 -
样品:
$scope.names=[];
$.each(response.data.records.slice(0,5), function(i, data) {
$scope.names.push(data);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
188 次 |
| 最近记录: |