附加来自两个函数jquery的代码 [英] appending code from two functions jquery

查看:43
本文介绍了附加来自两个函数jquery的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从这里开始是我的代码的副本

var userid ='UCLdin3PebPaIVQdIC7Lp-kg';
var devkey ='*******************************';


$(document).ready(function(){
    $.get(
        "https://www.googleapis.com/youtube/v3/channels",{
            part: 'contentDetails',
            id: userid,
            key: devkey},
        function(data){
            $.each(data.items, function(i, item){
                pid = item.contentDetails.relatedPlaylists.uploads;
                getVids(pid);
            })
        }
    );

    function getVids(pid){
        $.get(
            "https://www.googleapis.com/youtube/v3/playlistItems",{
                part: 'snippet',
                playlistId: pid,
                key: devkey},
            function(data){
                $.each(data.items, function(i, item){
                    console.log(item);
                    videoTitle = item.snippet.title;
                    videoid = item.snippet.resourceId.videoId;
                    getdur(videoid);
                    videoimg = item.snippet.thumbnails.standard.url;
                    videodesc = item.snippet.description;

                    name ='<h4 class="modal-title">'+videoTitle+'</h4>';
                    thumb ='<div class="ctr col-md-3 col-xs-12 ythumb"><a data-toggle="modal" href="#'+videoid+'"><img class="img-responsive" src="'+videoimg+'"></a></div>';
                    desc ='<div>'+videodesc+'</div>';
                    video ='<iframe src\"//www.youtube.com/embed/'+videoid+'\"></>';


                })
            }
        );
    }
    function getdur(videoid){
        $.get(
            "https://www.googleapis.com/youtube/v3/videos", {
                part:'contentDetails',
                id: videoid,
                key: devkey},
            function(data){
                $.each(data.items, function(i, item){
                    console.log(item)
                    videodur = item.contentDetails.duration;
                    videolength = videodur.replace("PT","").replace("H",":").replace("M",":").replace("S","");

                    var Duration ='<div id="length" class="ytime header cat_bar"><h3 class="catbg">'+videolength+'</h3></div>';


                    thumblen ='<div class="col-md-3 col-xs-12"><a data-toggle="modal" href="#'+videoid+'"><img class="img-responsive" src="'+videoimg+'"></a><div id="length" class="ytime header cat_bar"><h3 class="catbg">'+videolength+'</h3></div></div>'
                    $('#thumb-len').append(thumblen);


                })
            }
        );
    }
});





我想要做的是从var获取图像thumb和var duration并在同一个div中输出它们


and what I'm trying to do is get the image from var thumb and var duration and output them both in the same div


这是我计划如何工作的方式:  https://jsfiddle.net/wpqfm891/5/


这里是我现在得到的  http://beta.mdl-palissy.fr/youtube.php


它正确地输出时间,但我只为所有视频获得一个thumbanil虽然当我通过它自己附加getvids功能时它会按照计划放置视频(每个视频一个) )我可以补充说,只有缩略图才能解决这个问题

it's outputting the time correctly but i'm only getting one thumbanil for all the videos although when i append the getvids function by it's self it out puts the video's as planned (one per video) may i also add that it's only got this problem with the thumbnails


我也可以添加这个将使用bootstrap(我将修改代码以从css获取正确的类)来获取信息(如代码中所写)图像将链接(持续时间也将是奖金),此链接将链接到点击链接时
将显示的模式

may i also add the this will be done using bootstrap (I'll modify the codes to get the correct classes from he css) for info (as written in the code) the image will be in a link (the duration also would be a bonus), this link will be linked to a modal that will show when the link is clicked


我有可能做到这一点吗?

is there a way i could possibly do that ?


导致它现在不能正常工作

cause at the moment it isn't really working


我还可以补充说,如果你需要查看它,我已经离开了控制台日志

may i also add that I've left the console log for if you need to take a look at it


似乎只有缩略图只被给予一次,这是建议我使用诺言,但我看不出这会如何解决我的问题问题导致我一次性运行所有代码,但是(如果我正确地站在一起)
承诺是在运行了另一部分代码后运行的东西

after reading through my code it seems that it's only the thumbnails that is only being given once, it was suggested that i use promise but i couldn't see how this would solve my problem cause i run all the code in one go but (if i under stood correctly) promise is done for running something after another part of the code has been ran


在做了很多关于这个的回事之后我可能只是弄清楚我怎么可以用这个我想先把时间先附加然后使用promise然后将图像附加到div上之前附加了

right after doing lots of recherche about this i might of just figured out how i could use this i was thinking appending the time first then useing promise to then append the images to the div that was appended just before


i也发现appendTo对我有什么好处?

i also found appendTo would that be any good for me ?

我也在stackoverflow上发布了这个,但是没有最近的答案

http://stackoverflow.com/questions/35638481/appending-code-from-two- functions-jquery

http://stackoverflow.com/questions/35638481/appending-code-from-two-functions-jquery

推荐答案

在错误的论坛发帖。您需要发布此信息您工具或网络服务器的网络论坛,例如
http://forums.IIS.Net
http://forums.ASP.Net
 
Posting in wrong forum.  You need to post this in a web forum for you tool or web server such as http://forums.IIS.Net or http://forums.ASP.Net 


这篇关于附加来自两个函数jquery的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆