我正在尝试使用AngularJS和
PHP在英特尔XDK中使用ng-repeat填充离子列表.
我在阅读了一些问题后做了一些尝试,但没有任何效果.它会填充一个空列表,或者不显示任何内容.我的代码出了什么问题?
HTML:
<ion-view title="Temporada 2016" id="page1" style="background-color:#FFFFFF;">
<ion-content padding="true" class="has-header">
<div id="temporada2016-button-bar1" class="button-bar">
<button id="temporada2016-button2" style="color:#008BBB;" class="button button-light button-block button-outline active-bymyself">Notícias</button>
<a ui-sref="menu.fotos" id="temporada2016-button3" style="color:#008BBB;" class="button button-light button-block button-outline">Fotos</a>
</div>
<form id="temporada2016-form8" class="list">
<label class="item item-input" name="search_news">
<i class="icon ion-search placeholder-icon"></i>
<input type="search" placeholder="Pesquisar Notícia">
</label>
</form>
<!--<div class="item item-body list-container" id="temporada2016-list-item-container4">
<div id="temporada2016-markdown7" style="margin-top:0px;color:#666666;">
<p>{{title}}</p>
</div>
</div> -->
<ion-list class="widget uib_w_1 d-margins" data-uib="ionic/list" data-ver="0">
<ion-item class="item widget uib_w_2" data-uib="ionic/list_item" data-ver="0" ng-repeat="x in items">{{ x.TITLE }}</ion-item>
</ion-list>
</ion-content>
</ion-view>
角度:
.controller('temporada2016Ctrl', ['$scope', '$http', function ($scope, $http) {
$http.get("http://localhost/select-news.php").then(function(response){
console.log(response);
console.log(JSON.stringify(response));
$scope.items = response.data.records;
});
}])
PHP
<?php
include_once('conn.php');
$sql = $mysqli->query("SELECT * FROM news");
if($sql->num_rows > 0){
while($row = $sql->fetch_array(MYSQLI_BOTH)){
$registro = array(
"ID" => $row['id'],
"TITLE" => $row['title'],
"BODY" => $row['body']
);
$retorno[] = $registro;
}
}
$mysqli->close();
$retorno = json_encode($retorno);
echo $retorno;
?>
UPDATE
JSON
[{"ID":"0","TITLE":"Events of the Day","BODY":"Main Party at 22h!"}]
最佳答案 试着改变
$scope.items = response.data.records;
至
$scope.items = response.data;
或者在这里显示您的JSON