如何获取特定键的值对?

时间:2018-01-16 00:56:55

标签: javascript jquery html arrays json

我想要获取特定div的键值对,而只是我点击的div。现在它正在记录每个div的值。如何只获取我点击的特定div的值?我想在ajax成功期间更新,但我很难过如何仅更新某个div。关于我如何做到这一点的任何想法?

@PreAuthorize("isAuthenticated()")

这会更新动态生成的html代码(至少应该是这样)

$('.wrapper').on('click', '.bet-button', function() {
    var self = $(this);
    var gameId = self.attr('gameid');
    var awayVal = $('#' + gameId + ' input[name=betAmountAway]').val();
    var homeVal = $('#' + gameId + ' input[name=betAmountHome]').val();
    var awayId = $('#' + gameId + ' .bet-input-away').data('away-id');
    var homeId = $('#' + gameId + ' .bet-input-home').data('home-id');
    var pointTotals = $('#' + gameId + ' .total-points').val();
    console.log(pointTotals);
    var value = awayVal || homeVal;
    var id, value;




    if (awayVal) {
      id = awayId;
      value = awayVal;
    }
    if (homeVal) {
      id = homeId;
      value = homeVal;
    }

    if (!value) {
        alert('please enter a value!')
    } else {
        $.ajax({
          url: "---------" + userId + "/"+ gameId +"/"+ id +"/"+ value +"",
          type: "get",
        success: function(response) {



            // Makes the inputs inputable again.
            $('.bet-input-home').prop('disabled', false);
            $('.bet-input-away').prop('disabled', false);



            function update(){

                var currentSelection = $('#team-select').val();

                getGames().done(function(results){
                    $.each(results, function (i, gameData){
                        $.each(gameData, function(key, game){
                            var gamesHome = game.home_team_conference;
                            var gamesAway = game.away_team_conference;

                            if(gamesHome == currentSelection || gamesAway == currentSelection){
                                var gameId = game.id;
                                var pointTotal = game.total_points_bet;
                                var gameTime = game.game_time_hour;
                                var gameDate = game.game_time_date;
                                var homeId = game.home_team.id;
                                var awayId = game.away_team.id;
                                var homePoints = game.total_points_bet_on_hometeam;
                                var awayPoints = game.total_points_bet_on_awayteam;
                                var totalPoints = homePoints + awayPoints;

                                // $('#point-total').append(homePoints + awayPoints);

                            }

                        });
                    });
                })
            }
            update();

0 个答案:

没有答案