从 table 内容构建 videojs 播放列表?

Build videojs playlist from table content?

我想从 html table 中获取数据并从 tr 数据创建一个 videojs 播放列表。

我怎样才能做到这一点:

var playlist_content = [{
  sources: [{
    src: 'http://media.w3.org/2010/05/sintel/trailer.mp4',
    type: 'video/mp4'
  }],
  poster: 'http://media.w3.org/2010/05/sintel/poster.png'
}, {
  sources: [{
    src: 'http://media.w3.org/2010/05/bunny/trailer.mp4',
    type: 'video/mp4'
  }],
  poster: 'http://media.w3.org/2010/05/bunny/poster.png'
}];

player.playlist(playlist_content);

通过从这个table获取数据:

<table>
    <tr data-src="http://media.w3.org/2010/05/sintel/trailer.mp4" data-type="video/mp4" data-poster="http://media.w3.org/2010/05/sintel/poster.png"><td>Video 1</td></tr>
    <tr data-src="http://media.w3.org/2010/05/bunny/trailer.mp4" data-type="video/mp4" data-poster="http://media.w3.org/2010/05/bunny/poster.png"><td>Video 2</td></tr>
</table>

我的无效尝试:

var playlist_content = {};
$("table tr").each(function() {
    playlist_content[]["sources"]["src"]    = $(this).data('src');
    playlist_content[]["sources"]["type"]   = $(this).data('type');
    playlist_content[]["poster"]            = $(this).data('poster');
});
player.playlist(playlist_content);

解决了!

var playlist_content = [];
var index = 0;
$("table tr").each(function() {
    playlist_content[index]                      = {};
    playlist_content[index]["sources"]           = [];
    playlist_content[index]["sources"][0]        = {};
    playlist_content[index]["sources"][0]["src"] = $(this).data('src');
    playlist_content[index]["sources"][0]["type"]= $(this).data('type');
    playlist_content[index]["poster"]            = $(this).data('poster');
    index++;
});
player.playlist(playlist_content);