使用json feed获取Angular中的正确记录并传递数据

时间:2015-12-16 00:25:52

标签: javascript jquery angularjs json

所以我有一个有角度的服务,拿起一个json数据源,让我们说一个足球运动员名单 - 这个工作正常。我有一个家庭控制器,使用这样的代码将这些数据传递到主视图...

家庭控制器

.controller("mainController", function ($scope, playerService)
    {
    		
    		var promise = playerService.getPlayers();
    		promise.then(function (data)
    		{
    			
    			$scope.players = data;
    		});
    	
    })

主页视图

    <table class="table table-striped">
				<thead>
					<tr>
						<th>Name</th>
						<th>Club </th>
						<th>More?</th>
					</tr>
				</thead>
				<tbody>
					<tr data-ng-repeat="player in players">
						<td>{{player.name}}</td>
						<td>{{player.club}}&#8457;</td>
						<td><a href="#playercode/{{player.code}}">more</a></td>
					</tr>
				</tbody>
			</table>

正如您所看到的,然后将ID推送到URL

中的下一页

这将是第二个控制器的开始

var promise = playerService.getPlayers();
	promise.then(function (data)
	{
		
		var code = $routeParams.code;
		
		$scope.players = data;
		$scope.whichResult = $routeParams.code;
			
			console.log($scope.players);
			console.log($scope.whichResult);
			
	});

我现在需要做的是查看最后一个数据集的结果,只是查看我需要的数据,但我不知道该怎么做。

我在$ scope.players中设置了日期,在$ scope.whichResult中设置了播放器代码,但我如何过滤以获得我想要的播放器?

我使用ngRoute设置了2条主要路线

var playerApp = angular.module('playerApp', ['ngRoute']);
	

playerApp.config(function($routeProvider) {
			$routeProvider
	
				// route for the home page
				.when('/', {
					templateUrl : 'app/views/home/homeview.html',
					controller  : 'mainController'
				})
	
				// route for the about page
				.when('/playercode/:code', {
					templateUrl : 'app/views/player/playerview.html',
					controller  : 'playerController'
				})
	
				
		});
		

任何帮助非常感谢

1 个答案:

答案 0 :(得分:1)

URL: http://server.com/index.html#/Chapter/1/Section/2?search=moby

// Then
$routeParams ==> {chapterId:'1', sectionId:'2', search:'moby'}

参考:Angular Docs

要创建网址,您可以使用$location例如:

$location.path('/chapter/' + Id + '/section/' + secId);