Jquery $ each()替代

时间:2014-03-13 08:31:38

标签: javascript jquery

我正在使用Jquery开发webapp,并使用$ each()来迭代某些值。现在在Firebug中我观察到有多个GET调用,例如GET http://localhost/Centrifuge42/forecast.py?data。那么在单个GET调用中有没有办法做到这一点?我的代码如下:

function showGraph(de, node, futureData) {
    //alert("show");
    //alert(futureData);
    var trcounter = $('#timeContainer tr').length;
    //alert(trcounter);
    if(trcounter > 0)
        $('#timeContainer tr').remove();
    var dataLen = de.length;
    console.log(dataLen);
    $.each(de, function(key, val){
    //$('#timeContainer').find('tr',function(){})
    var dataLen = de.length;
    //alert(val);
    //alert(node[key]);
    //alert(dataLen);
    var containertr = document.createElement("tr");
    var containertd = document.createElement("td");
    containertr.setAttribute('id', 'forecasttr'+key);
    //containertr.setAttribute('onClick', "showFutureForecast('forecast"+key+"', '"+node[key]+"');");
    var containerHiddenNode = document.createElement("input");
    var containerHiddenTime = document.createElement("input");

    containerHiddenNode.setAttribute('type', 'hidden');
    containerHiddenNode.setAttribute('value', val);
    containerHiddenNode.setAttribute('id', 'forecastVal');

    containerHiddenTime.setAttribute('type', 'hidden');
    containerHiddenTime.setAttribute('value', node[key]);
    containerHiddenTime.setAttribute('id', 'forecastNode');

    var containertdHTML = "<div id='chart"+key+"' class='chart'></div>";
    containertd.setAttribute('style','background-color:#FF99FF');
    containertd.innerHTML = containertdHTML;
    containertd.appendChild(containerHiddenNode);
    containertd.appendChild(containerHiddenTime);
    containertr.appendChild(containertd);
    $('#timeContainer').append(containertr);

    graph = new SimpleGraph("chart"+key, {
          "data": val, 
          "title": node[key]+" Forecast",
          "xlabel": "Duration",
          "ylabel": "Time Series"  
        });
      //body.innerHTML += "<div id='infobox' class='infobox' style='display:none;'>Test</div>";
      var chart = document.getElementById("chart"+key);
      var elem = document.createElement('span');
      //elem.setAttribute('id', 'infobox');
      elem.setAttribute('class', 'infobox');
      elem.setAttribute('style', 'display:none;');
      //elem.innerHTML = 'Test';
      chart.appendChild(elem);
      var idat = "chart"+key;
      var future = parseInt(futureData);
      //alert(-future);
      var data = $("#"+idat+" circle").slice(-future).attr('fill');
      console.log(data);
      //$("#"+idat+" circle:nth-last-child("+-future+")").attr("fill", "#ff0000");
      if(typeof futureData != 'undefined')
      {
       if (futureData!=0){
        $("#"+idat+" circle").slice(-future).attr("style", "stroke:#FF0000");
        }
      }
    //console.log(val);
    });

0 个答案:

没有答案