同一个接口里的数据,多处用小方法

1、有时获取一个后台接口,页面展示会多处用到,不用多次调用同一个接口,可以调用一次,把页面调用这个接口的数据,一下全展示出来;

如例:

$("#bootServerList"), $("#designateServerList")两处都要用,可以仿照使用
apiGet(url,function (data) {
        if(data.status==0){
            var html = '<ul class="bootServerList">'
            var options = ""
            data.content.forEach(function (data) {
                html += '<li onclick="getGroupList(this,\''+data.uuid+'\')">' +
                    '<div class="title">'+
                    '<img src="images/sanjaio.png">'+
                    '<img src="images/server0.png">'+
                    '<span>'+data.name+'</span>'+
                    '<span>(</span>'+
                    '<span id="onlineComputer">100</span>'+
                    '<span>/</span>'+
                    '<span id="sumComputer">1000</span>'+
                    '<span>)</span>'+
                    '</div>' +
                    '<div id="'+data.uuid+'"></div>' +
                    '</li>';
                options += '<option value="'+data.uuid+'">'+data.name+'</option>'
            })
            html += '</ul>';
            $("#bootServerList").html("").html(html)
            $("#designateServerList").html("").html(options)
            // console.log(url+'getBootServerList?token='+localStorage.getItem("token"),100)
        }else{
            console.log("错误");
        }

猜你喜欢

转载自www.cnblogs.com/chaojimali/p/9375147.html
今日推荐