我正在尝试从连接到动态数据库的远程服务器获取此数组。
据我从离子论坛上读到,我需要使用AngularJS中的$http function,但我对AngularJS很新,目前的例子对我来说似乎太复杂了this one。
我正在尝试将this example转换为Remote JSON。
HTML部分:
<ion-list>
<ion-item ng-repeat="item in items"
item="item"
href="#/item/{{item.id}}">
Person {{ item.id }} Name {{ item.name }}
</ion-item>
</ion-list>
数组部分:
var friends = [
{ id: 1, name: 'G.I. Joe' },
{ id: 2, name: 'Miss Frizzle' },
{ id: 3, name: 'Scruff McGruff' },
{ id: 4, name: 'G.I. Joe' },
{ id: 5, name: 'Miss Frizzle' },
{ id: 6, name: 'Scruff McGruff' },
{ id: 7, name: 'G.I. Joe' },
{ id: 8, name: 'Miss Frizzle' },
{ id: 9, name: 'Scruff McGruff' },
{ id: 10, name: 'G.I. Joe' },
{ id: 11, name: 'Miss Frizzle' },
{ id: 12, name: 'Scruff McGruff' },
{ id: 13, name: 'G.I. Joe' },
{ id: 14, name: 'Miss Frizzle' },
{ id: 15, name: 'Scruff McGruff' },
{ id: 16, name: 'G.I. Joe' },
{ id: 17, name: 'Miss Frizzle' },
{ id: 18, name: 'Ash Ketchum' }
];
我试过了:
$scope.items = jsonp('http://www.garsoncepte.com/json.php');
$scope.items = $http.jsonp('http://www.garsoncepte.com/json.php');
var url = "http://www.garsoncepte.com/json.php";
$scope.items = $http.jsonp(url);
答案 0 :(得分:1)
由于你正在使用jsonp,你需要设置回调函数JSON_CALLBACK
并在回调函数中设置你的项目。
$scope.items = [];
var url = "http://www.garsoncepte.com/json.php?callback=JSON_CALLBACK";
$http.jsonp(url)
.success(function(data) {
$scope.items = data;
});
= DEMO =