JSON jQuery if语句

JSON jQuery if语句,jquery,json,if-statement,Jquery,Json,If Statement,我希望能够从deal.options对象中附加title\u优惠券值,但前提是它存在。如果选项不存在,我想从数据.交易获取标题.优惠券。下面的代码可以工作,但它显然是从deal.options和data.deal返回title.coupon。有人能帮我构造if语句吗 这是我当前的代码: $.each(data.deal, function (x, deal) { $('#container').after('<tr><td>' + this.title_coupo

我希望能够从
deal.options
对象中附加
title\u优惠券
值,但前提是它存在。如果
选项
不存在,我想从
数据.交易
获取
标题.优惠券
。下面的代码可以工作,但它显然是从
deal.options
data.deal
返回
title.coupon
。有人能帮我构造if语句吗

这是我当前的代码:

$.each(data.deal, function (x, deal) {
    $('#container').after('<tr><td>' + this.title_coupon + '</td><td>' + this.id + '</td></tr>');
    $.each(deal.options, function (x, options) {
        $.each(options, function (x, deal) {
            $('#container').append('<tr><td>' + this.title_coupon + '</td><td>' + this.id + '</td></tr>');
        });
    });
});
$.each(data.deal,function(x,deal){
$(“#容器”)。之后(“”+this.title_优惠券+“”+this.id+“”);
$.each(deal.options,function(x,options){
美元。每个(选项、功能(x、交易){
$(“#容器”).append(“”+this.title_优惠券+“”+this.id+“”);
});
});
});
那么:

$.each(data.deal, function (x, deal) {
    var found = false;
    $.each(deal.options, function (x, options) {
        $.each(options, function (x, deal) {
            $('#container').append('<tr><td>' + this.title_coupon + '</td><td>' + this.id + '</td></tr>');
            found = true;
        });
    });
    if (!found) {
        $('#container').after('<tr><td>' + this.title_coupon + '</td><td>' + this.id + '</td></tr>');
    }
});
$.each(data.deal,function(x,deal){
var=false;
$.each(deal.options,function(x,options){
美元。每个(选项、功能(x、交易){
$(“#容器”).append(“”+this.title_优惠券+“”+this.id+“”);
发现=真;
});
});
如果(!找到){
$(“#容器”)。之后(“”+this.title_优惠券+“”+this.id+“”);
}
});

if语句在哪里?它不在那里,这就是我要找的:)你能提供JSON和预期的HTML吗?
jquery
只是一个
javascript
库,使用简单的
if()
语句并获取条件数据。这很难理解。您多次声明
x
,每次都隐藏外部实例。与
交易相同