如果值= false,我将如何通过动态内容并附加内容?

时间:2018-03-02 16:44:50

标签: javascript jquery json

我试图迭代我已经包含在我的文件中的一些JSON,并且一切似乎都工作正常,直到我想将我的图标添加到每个crisbox图标div中。知道可能出了什么问题吗?如果我的JSON对象的值=== true,我想添加一个图标,如果值=== false,我想添加一个图标。

$.each(stakeBox, function (i, stakeBoxData) {
    var jsonDate = stakeBoxData.data_change_date;
    var winLoss = stakeBoxData.win;
    var points = stakeBoxData.amount_stakebox;
    var winLoss = stakeBoxData.win;
    var id = stakeBoxData.id;

    if (stakeBoxDay < jsonDate) {
        var self = $(this);
        console.log(this.win);
        $('.stakebox-container').append('\
        <div id="' + id + '" class="stakebox-message-container">\
            <div id="stakebox-icon"></div>\
            <div><h5 id="stakebox-game"></h5></div>\
            <div><h5 id="stakebox-points">' + points + '</h5></div>\
        </div>\
    ');

        if (this.win === true) {
            $('#stakebox-icon').append('<i class="far fa-smile face"></i>');
        } else {
            $('.stakebox-message-container').css('background', '#a20000');
            $('#stakebox-icon').append('<i class="far fa-frown face"></i>');
        };
        // console.log(i);
    } else {
        // console.log('nope');
    }
});

以下是一些供参考的JSON:

var stakeBox = [{
    id: "1",
    amount: "40.00",
    user_id: "1",
    amount_stakebox: "33",
    win: true,
    data_change_date: "20180229",
    username: "bkessler",
    game_id: "1380",
    team_id: "791",
    status: "1"
}, {
    id: "2",
    amount: "1.00",
    user_id: "1",
    amount_stakebox: "4124124",
    win: false,
    data_change_date: "20180429",
    username: "bkessler",
    game_id: "1380",
    team_id: "791",
    status: "1"
}];

0 个答案:

没有答案