Javascript 如何将json数据项转换为变量?
我正在处理来自电视api的Json数据。从这个api中,我想使用“tvshow.eption.ratings.loved”值。如何将此值链接到以下内容 $scope.like=tvshow.eption.ratings.loved;我想用这个做一些数学运算。如何将这个冗长的json文本转换为$scope.like?我应该在代码中的什么位置包含它?请帮忙Javascript 如何将json数据项转换为变量?,javascript,json,angularjs,Javascript,Json,Angularjs,我正在处理来自电视api的Json数据。从这个api中,我想使用“tvshow.eption.ratings.loved”值。如何将此值链接到以下内容 $scope.like=tvshow.eption.ratings.loved;我想用这个做一些数学运算。如何将这个冗长的json文本转换为$scope.like?我应该在代码中的什么位置包含它?请帮忙 var app = angular.module('MyApp',[]); app.controller("mainController",
var app = angular.module('MyApp',[]);
app.controller("mainController", function ($scope, $http, $filter){
$scope.filteredItems = [];
$scope.pagedItems = [];
$scope.curPage = 1;
$scope.init = function() {
$http.jsonp('http://api.trakt.tv/calendar/premieres.json/' + $scope.apiKey + '/' + apiDate + '/' + 30 + '/?callback=JSON_CALLBACK').success(function(data) {
angular.forEach(data, function(value, index){
angular.forEach(value.episodes, function(tvshow, index){
tvshow.date = date;
$scope.results.push(tvshow);
angular.forEach(tvshow.show.genres, function(genre, index){
//Only add to the availableGenres array if it doesn't already exist
var exists = false;
angular.forEach($scope.availableGenres, function(avGenre, index){
if (avGenre == genre) {
exists = true;
}
});
});
});
});
};
}).error(function(error) {
});
};
app.$inject = ($scope, $filter);
});
之后
加
在这个循环中添加
angular.forEach(value.episodes, function(tvshow, index) {
// .... code
$scope.loved.push(tvshow.ratings.loved);
})
如果您只想显示每个项目的评分,则需要添加此模板
<span class="label"><i class="icon-thumbs-up"></i> {{tvshow.show.ratings.loved}}</span>
<span class="label"><i class="icon-thumbs-down"></i> {{tvshow.show.ratings.hated}}</span>
{{tvshow.show.ratings.loved}
{{tvshow.show.ratings.haved}
结果,您得到的数组中包含所有“喜爱的评级”
$scope.groupedItems = [];
加
在这个循环中添加
angular.forEach(value.episodes, function(tvshow, index) {
// .... code
$scope.loved.push(tvshow.ratings.loved);
})
如果您只想显示每个项目的评分,则需要添加此模板
<span class="label"><i class="icon-thumbs-up"></i> {{tvshow.show.ratings.loved}}</span>
<span class="label"><i class="icon-thumbs-down"></i> {{tvshow.show.ratings.hated}}</span>
{{tvshow.show.ratings.loved}
{{tvshow.show.ratings.haved}
结果,您得到的数组中包含所有“喜爱的评级”
$scope.groupedItems = [];
加
在这个循环中添加
angular.forEach(value.episodes, function(tvshow, index) {
// .... code
$scope.loved.push(tvshow.ratings.loved);
})
如果您只想显示每个项目的评分,则需要添加此模板
<span class="label"><i class="icon-thumbs-up"></i> {{tvshow.show.ratings.loved}}</span>
<span class="label"><i class="icon-thumbs-down"></i> {{tvshow.show.ratings.hated}}</span>
{{tvshow.show.ratings.loved}
{{tvshow.show.ratings.haved}
结果,您得到的数组中包含所有“喜爱的评级”
$scope.groupedItems = [];
加
在这个循环中添加
angular.forEach(value.episodes, function(tvshow, index) {
// .... code
$scope.loved.push(tvshow.ratings.loved);
})
如果您只想显示每个项目的评分,则需要添加此模板
<span class="label"><i class="icon-thumbs-up"></i> {{tvshow.show.ratings.loved}}</span>
<span class="label"><i class="icon-thumbs-down"></i> {{tvshow.show.ratings.hated}}</span>
{{tvshow.show.ratings.loved}
{{tvshow.show.ratings.haved}
结果,您得到的数组具有所有“喜爱的评级”为了正确地帮助您,我们需要知道JSON是什么样子;)另外,您通常不想公开发布API密钥。@jValdron-没问题,这是电视时间表。任何人都可以注册。为了正确地帮助您,我们需要知道JSON是什么样子;)另外,您通常不想公开发布API密钥。@jValdron-没问题,这是电视时间表。任何人都可以注册。为了正确地帮助您,我们需要知道JSON是什么样子;)另外,您通常不想公开发布API密钥。@jValdron-没问题,这是电视时间表。任何人都可以注册。为了正确地帮助您,我们需要知道JSON是什么样子;)另外,您通常不想公开发布API密钥。@jValdron-没问题,这是电视时间表。任何人都可以注册。