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
,每次都隐藏外部实例。与交易相同
。