http://jsfiddle.net/rzgWr/19/-演示
我很棒getdata.php
include 'db.php';
$sel = mysqli_query($link,"select * from products");
$data = array();
while ($row = mysqli_fetch_array($sel)) {
$data[] = array("name"=>$row['name'],"shirt"=>$row['shirt'],"pants"=>$row['pants'],"shoes"=>$row['shoes']);
}
echo json_encode($data);
演示的下一个代码值为$ scope.players:
function MyCtrl($scope, filterFilter) {
$scope.usePants = {};
$scope.useShirts = {};
$scope.useShoes = {};
$scope.players = [
{name: 'Bruce Wayne', shirt: 'XXL', pants: '42', shoes: '12'},
{name: 'Wayne Gretzky', shirt: 'XL', pants: '38', shoes: '10'},
{name: 'Michael Jordan', shirt: 'M', pants: '32', shoes: '9'},
{name: 'Rodman', shirt: 'XSXL', pants: '42', shoes: '11'},
{name: 'Jake Smitz', shirt: 'XXL', pants: '42', shoes: '12'},
{name: 'Will Will', shirt: 'XXLL', pants: '42', shoes: '12'},
{name: 'Youasdf Oukls', shirt: 'XL', pants: '38', shoes: '10'},
{name: 'Sam Sneed', shirt: 'XL', pants: '38', shoes: '10'},
{name: 'Bill Waxy', shirt: 'M', pants: '32', shoes: '9'},
{name: 'Javier Xavior', shirt: 'M', pants: '32', shoes: '9'},
{name: 'Bill Knight', shirt: 'M', pants: '32', shoes: '9'},
{name: 'One More', shirt: 'M', pants: '32', shoes: '9'},
{name: 'Player One', shirt: 'XXL', pants: '42', shoes: '11'},
{name: 'Space Cadet', shirt: 'XXL', pants: '42', shoes: '12'},
{name: 'Player Two', shirt: 'XXXXL', pants: '42', shoes: '12'}
];
如何从getdata.php加载$ scope.players?
谢谢。
如何正确执行?
myApp.controller('playersCrtl', function ($scope, $http, $timeout) {
$http.get('getdata.php').success(function(data){
$scope.players = data;
});