2013-05-02 42 views
0

我正在使用JPlayer作为网站。 现在,我想从路径和艺术家名称的表格创建播放列表。 现在我所做的是将表添加到页面,现在,使用forEach我试图 读取路径并将其添加到播放列表。但不知何故,我很困惑.. 看一看 这是我用来抓取路径的代码,它工作正常通过使用jPlayer为jPlayer读取表中的歌曲来创建动态播放列表

<script type="text/javascript"> 
    $(document).ready(function() { 
     $('#songsPathGridView tr').each(function() { 
      if (!this.rowIndex) return; // skip first row 
      var path = this.cells[0].innerHTML; 
      alert(path); 

     }); 
    }); 
</script> 

,现在这是我有播放列表(硬编码值)。现在,如果它是在HTML或东西我可能追加这条道路给它,但因为它是jQuery代码,请告诉我该怎么做.. 这里是播放列表代码

<script type="text/javascript"> 
    $(document).ready(function() { 
     var songName = "Song1"; 
     var theArtist = "The Artist"; 
     var myPlaylist = [ 
      { 
       mp3: 'music/Mad.mp3', oga: 'mix/1.ogg', title: songName, artist: theArtist, 
      }, 
      { 
       mp3: 'mix/EssentialViolet.mp3', oga: 'mix/2.ogg', title: songName, artist: theArtist, cover: 'mix/2.jpg' 
      } 
     ]; 
     $('body').ttwMusicPlayer(myPlaylist, { 
      autoPlay: false, 

      jPlayer: { 
       swfPath: '../plugin/jquery-jplayer' //You need to override the default swf path any time the directory structure changes 
      } 
     }); 
    }); 
</script> 

不知怎的,我想要得到的文件路径和动态添加它。请帮忙,谢谢。

回答

1

我倒要看看你使用表的HTML代码,因为它会影响到施工,但实际上这种方法应该工作:

$(document).ready(function() { 

    var myPlaylist = [{}]; // Empty object to push into 

    $('#songsPathGridView tr').each(function() { 
     if (!this.rowIndex) return; // skip first row 
     // Push each row's data into the myPlaylist variable 
     // Expects MP3 path at column 0, title at column 1, artist at column 2 
     myPlaylist.push({ mp3: this.cells[0].innerHTML, title: this.cells[1].innerHTML, artist: this.cells[2].innerHTML }); 
    }); 

    $('body').ttwMusicPlayer(myPlaylist, { 
     autoPlay: false, 
     jPlayer: { 
      swfPath: '../plugin/jquery-jplayer' //You need to override the default swf path any time the directory structure changes 
     } 
    }); 

}); 
+0

有这个没有HTML代码中,标记是动态完成的,只有表格放置在表格路径中。让我试试你的代码,并让你知道。 – designerNProgrammer 2013-05-02 17:13:24

+0

好的,如果表格只有一列(对于路径),您可能想删除代码',title:this.cells [1] .innerHTML,artist:this.cells [2] .innerHTML',因为它需要2个额外的表中的列填充艺术家和歌曲标题值。 – 2013-05-02 17:14:57

+0

你能编辑你的代码片段吗? – designerNProgrammer 2013-05-02 17:17:02