1
我瞎了嗎?爲什麼我不能從這個變量中得到這個值到我的變量'progress'中? 它沒有保存爲一個字符串,'obj.songProgress [i] .songProgress'輸出到控制檯,但它自己的進度不會。進一步變量被分配好。指定從JSON獲得的變量
$(document).on("click",".profTemp", function()
{
if(!$(this).hasClass('selected'))
{
var selectedUser;
var previous = null;
var current = null;
var assigned = false;
var currentSong;
var previousSong;
var previousUser = null;
selectedUser = $(this).children('span').text();
selectedUser = selectedUser.trim();
$('.profTemp').removeClass('selected');
clearInterval(pollUser);
$(this).toggleClass('selected');
pollUser = setInterval(function()
{
console.log(selectedUser);
$.ajax({
url: '/getJSON',
dataType: 'json',
success: function(response) {
obj = JSON.parse(response);
var changeTo;
var deviceID;
var playing;
var progress;
for(var i = 0; i < obj.clients.length; i++)
{
if(selectedUser == obj.clients[i].userName)
{
console.log(selectedUser + " inside if");
current = JSON.stringify(obj.clients[i]);
changeTo = obj.clients[i].uri;
device = obj.clients[i].deviceID
playing = obj.clients[i].isPlaying;
currentSong = obj.clients[i].songName;
}
}
for(var i = 0; i < obj.songProgress.length; i++)
{
if(selectedUser == obj.songProgress[i].userName)
{
progress = obj.songProgress[i].songProgress;
console.log(obj.songProgress[i].songProgress + progress);
}
}
這裏的JSON:
{
"clients":[
{
"userName":"test1 test1",
"albumArt":"https://i.scdn.co/image/e0f8a9160f4eaf4bee5816ca6f7833acbabf67ce",
"songName":"Everyday",
"artistName":"Angie Stone",
"albumName":"Black Diamond",
"songLength":1498831947299,
"isPlaying":false,
"uri":"spotify:track:7okKZ5JfRIJBcqKhX2fTmU",
"deviceID":"0a00d5d75dc4809ed68b92b4d998e71f36a69041",
"trackID":"7okKZ5JfRIJBcqKhX2fTmU",
"songProgress":101580
},
{
"userName":"testaccount",
"albumArt":"https://i.scdn.co/image/1aa6bb570db21d1b5edd3071e39c8ac0530dd99d",
"songName":"Tyrant (feat. Jorja Smith)",
"artistName":"Kali Uchis",
"albumName":"Tyrant (feat. Jorja Smith)",
"songLength":1498832434724,
"isPlaying":true,
"uri":"spotify:track:6u24cRDn2mTKcXxxtgmIsV",
"deviceID":"2198676338ce85949579e2d6350962b6552bbbf5",
"trackID":"6u24cRDn2mTKcXxxtgmIsV",
"songProgress":1501
}
],
"songProgress":[
{
"userName":"test1 test1",
"songProgress":101580
},
{
"userName":"testaccount",
"songProgress":1501
}
]
}
能否請您分享JSON? – Shiladitya
剛剛對帖子進行了編輯 – Toby