无法访问对象的属性

时间:2017-04-11 10:55:50

标签: javascript object

我有三个console.log调用我的代码中进行测试:

console.log(data);
console.log(data.url);
console.log(data["url"]);

控制台中的输出是:

mySC.js:85 Object {}songArtist: "Kasbo" songTitle: "Kasbo - Found You (Feat. Chelsea Cutler) " thumbnail: "https://i1.sndcdn.com/artworks-000216213225-csqjf0-t500x500.jpg" url: "https://soundcloud.com/kasbomusic/found-you-feat-chelsea-cutler"__proto__: Object
mySC.js:86 undefined
mySC.js:87 undefined

我的错误在哪里?为什么我没有得到这个对象的网址?

修改

这些是我传递数据的函数调用

playSC(iFrame, song, false, function(data) {
  updateSongInfo(data);
});

function updateSongInfo(data) {
  updateLink(data.url);

  console.log(data);
  console.log(data.url);
  console.log(data["url"]);
}

function playSC(player, song, autoPlay, callback) {
  player.load(song, {
    auto_play: autoPlay,
    callback: function () {
      var data = getSCinfo(song);
      if(callback) {
        callback(data);
      }
    }
  });
}

function getSCinfo(song){
  var scUrl = 'https://soundcloud.com/oembed.json?maxheight=200&url='+song;
  var computedData = {};

  getAjax(scUrl, function(data) {
    var jsonData = JSON.parse(data);
    var thumbHttps = jsonData.thumbnail_url.replace(/^http:\/\//i, 'https://');
    var titleOnly = jsonData.title.split("by");

    computedData.thumbnail = thumbHttps;
    computedData.songTitle = titleOnly[0];
    computedData.songArtist = jsonData.author_name;
    computedData.url = song;
  });

  return computedData;
}

0 个答案:

没有答案