gpt4 book ai didi

javascript - 难以理解和创建动态 JavaScript 对象

转载 作者:行者123 更新时间:2023-12-02 20:32:16 26 4
gpt4 key购买 nike

我希望我的代码能够 self 解释,我已经快到了,我只是卡在如何将可选数据合并到具有多个级别的 JSON 对象中(是这样吗?)

//get video list - example: video1.flv;test23.flv;Grabledable.flv
var files = j('.videos').html().split(';');
// assume first we have one video, so no need of playlist
var isplaylist = false;
// check if there are actually more than one video
if (files.length > 1) {
isplaylist = true;
var playlist = new Array(); // is this right? I want to add this to the video var
for (var i in files) {
playlist[] = {
url: files[i],
title: 'Video ' + i
};
}
};

//here's where the trouble starts
var video = {
plugins: {
controls: {
playlist: isplaylist,
//i cut out all irrelevant extra data
}
},
clip: {

url: files[0],
// ONLY DO THIS IF isplayer == false;
wmode: 'opaque',
baseUrl: "/video/",
autoPlay: false
},

// from here on this should only occur if isplayer == true;
// following is the way I want it attached from var playlist
playlist: [{
url: 'video1.flv',
title: 'Video 0'
},
{
url: 'test23.flv',
title: 'Video 1'
},
{
url: 'Grabledable.flv',
title: 'Video 2'
}]
};

我的目标是此处列出的格式:http://flowplayer.org/plugins/javascript/playlist.html在 JavaScript 编码部分下。

最佳答案

如果我没记错的话,你想要这样的东西:

var video = {
plugins: {
controls: {
playlist: false
}
},
clip: {
wmode: 'opaque',
baseUrl: "/video/",
autoPlay: false
}
}

// check if there are actually more than one video
if(files.length > 1){
video.plugins.controls.playlist = true;
var playlist = [];
for ( var i = 0, l = files.length; i < l; i++ )
{
playlist.push({url: files[i], title: 'Video '+ i});
}
video.playlist = playlist;
}
else {
video.clip.url = files[0];
}

相应的条目(例如video.playlistvideo.clip.url)是动态添加的。切勿使用 for ( ... in ...) 结构遍历数组!

关于javascript - 难以理解和创建动态 JavaScript 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3899330/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com