从ajax向水平推送列表添加垂直元素

时间:2013-07-15 14:52:38

标签: jquery ajax json

也许是一个技巧问题。我试图通过ajax / json提取数据来制作高尔夫记分卡。

以下是我获得记分卡的方法。

PHP:

$scorecard = array();
$players = array();
$data = array();

$result = mysqli_query($con,"SELECT * FROM ga_turndata WHERE fk_turnid = 1 ORDER BY hole_no ASC LIMIT 18");
while($row = mysqli_fetch_array($result)){
    $scorecard[] = array('hole' => $row['hole_no'], 'par' => $row['par'], 'hcp' => $row['hcp']);
}

$players[] = array('user' => 'Jane Doe', 'id' => '89', 'useraStrokes' => '5');
$players[] = array('user' => 'Jemaine Dice', 'id' => '245', 'useraStrokes' => '17');
$players[] = array('user' => 'Jimmie Gallon', 'id' => '16', 'useraStrokes' => '13');

$data = array('scorecard' => $scorecard, 'players' => $players); 

在stackoverflow用户的帮助下,我让它通过json发送2个不同的数组。

我得到这样的数据:

$.getJSON('http://mypage.com/json/scorecard.php', function(data) {

        var array = [];
        var c = 0;

        $.each(data.players, function(i, player){
            eval("player" + i + " = player.user");
            c++;
        });

        $.each(data.scorecard, function (i, scorecard) {

            array.push($("#theholes").append("<li><div class='holeinfo'>"+scorecard.hole+"</div><div id='players'>Here i want to dynamicly add players from the first $.each</div></li>"));

        });
});

获得18洞是没有问题的,但是无法想象我是如何将玩家动态地添加到$ each循环中的?

希望这有道理!?!希望得到帮助并提前感谢: - )

0 个答案:

没有答案