Javascript JS文件中的输出条件

Javascript JS文件中的输出条件,javascript,php,Javascript,Php,我有一个函数,它通过API从数据库加载所有从Steam服务接收到的项目。该表有一个is_draw列,默认值为0。如果用户单击该按钮,则is_draw值将更改为1 我在网站上有一个块,其中显示了所有这些项目,尽管显示了来自JS的所有项目。对于那些已退出值1的项目,有必要添加信息文本 我的JS文件: items.forEach( (item) => { itemsCount++; console.l

我有一个函数,它通过API从数据库加载所有从Steam服务接收到的项目。该表有一个
is_draw
列,默认值为
0
。如果用户单击该按钮,则
is_draw
值将更改为
1

我在网站上有一个块,其中显示了所有这些项目,尽管显示了来自JS的所有项目。对于那些
已退出
1
的项目,有必要添加信息文本

我的JS文件:

items.forEach( (item) => {
                        itemsCount++;
                        console.log(item.withdraw);
$('.invent-main').append('<div id="item" title="'+item.market_hash_name+'" data-id="'+item.assetid+'" data-price="'+item.price+'" onclick="Inventory.selectItemInventory('+item.assetid+')" class="rarity-'+item.type+'">\n' +
                            '<img src="https://steamcommunity-a.akamaihd.net/economy/image/'+item.classid+'/60fx60f" class="invent-item">\n' +
                            '<div class="item-bottom">\n' +
                            ' <div class="item-bottom-l">\n' +
                            ''+item.price+'\n' +
                            ' </div>\n' +
                            ' <div class="item-bottom-r">\n' +
                            '<i class="fa fa-rub" aria-hidden="true"></i>\n' +
                            ' </div>\n' +
                            '</div>\n' +
                            '</div>');
                    });
var_转储($draw);退出演示给我看:

array(1) { [0]=> object(stdClass)#570 (12) { ["id"]=> int(542) ["assetid"]=> string(11)
 "18235855825" ["market_hash_name"]=> string(29) "Divinations of the Nothl Haze" ["classid"]=> string(192) 
"-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KW1Zwwo4NUX4oFJZEHLbXQ5BhMYY49vRpiRVjVStup3tnaXVxgLAtZpYWqLTh02_b3fzJW5NCJnIGRkrmkYeqGkjwFupEkiL6Z8d-m2QeyrUdsNj30JNfDJgBoZVDW-QO9lO27m9bi607_CJYN" 
["price"]=> float(36.73) ["steamid"]=> string(17)
 "76561198044161202" ["type"]=> string(4) "card" ["bot"]=> string(1) "1"
["status"]=> int(0) ["created_at"]=> string(19) 
"2020-02-27 01:47:12" ["updated_at"]=> string(19) "2020-03-06 20:34:41" ["is_withdraw"]=> int(1) } }
据我所知,我得到了一个数组作为结果,我需要从is_draw字段中获取每件事情的值,我如何才能正确地执行它

现在
console.log
say me
undefined

将您的console.log(item.draw)更改为console.log(item.is\u draw)并查看发生了什么

此外,item::where()将返回整个item模型,而不仅仅是一个字段。您需要执行以下操作:

item.is_draw.is_draw(或者在php中更好地将is_draw数组值设置为$draw->is_draw)

这将为所有具有is_draw字段值1的数组提供值。有关更多信息,请参阅此链接


据我所知,您可以使用javascript数组筛选方法筛选出值为1的is_Draw字段。console.log未定义,因为您使用的是item.Draw而不是item.is_Drawhops,我的错。现在全部显示为:P但我如何才能在JS中导出条件
if(is_-draw==1){Item with 1 number}else{}
if
is_-draw
0,不显示任何内容。
array(1) { [0]=> object(stdClass)#570 (12) { ["id"]=> int(542) ["assetid"]=> string(11)
 "18235855825" ["market_hash_name"]=> string(29) "Divinations of the Nothl Haze" ["classid"]=> string(192) 
"-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KW1Zwwo4NUX4oFJZEHLbXQ5BhMYY49vRpiRVjVStup3tnaXVxgLAtZpYWqLTh02_b3fzJW5NCJnIGRkrmkYeqGkjwFupEkiL6Z8d-m2QeyrUdsNj30JNfDJgBoZVDW-QO9lO27m9bi607_CJYN" 
["price"]=> float(36.73) ["steamid"]=> string(17)
 "76561198044161202" ["type"]=> string(4) "card" ["bot"]=> string(1) "1"
["status"]=> int(0) ["created_at"]=> string(19) 
"2020-02-27 01:47:12" ["updated_at"]=> string(19) "2020-03-06 20:34:41" ["is_withdraw"]=> int(1) } }
$withdraw = Item::where('is_withdraw', '=', 1)->get();
    $items[] = [
        'id' => $info['id'],
        'classid' => $item['icon_url'],
        'price' => round($price, 2),
        'type' => $type,
        'is_withdraw' => $withdraw->is_withdraw
    ];
const result = items.filter(item => item.is_withdraw == 1);