项目中有个需求是判断商品是否为VIP专享,是的话就带VIP图标,在模版直接读取数据使用if condition是可以实现的,但是在用js实现“点击加载更多”时,在js代码块里无法实现if condition判断,该怎么办?
初始加载代码:

{$vo.goods_title}
{$vo.goods_title2}
起拍价:¥{$vo.start_price}
倒计时
然后通过ajax实现点击加载更多,代码如下:
var nStart = 5;
$('#more').click(function() {
var _this = $(this);
if (nStart >= {$total}) {
_this.text('更多商品正在上架中...');
return false;
}else{
$.post("{:U('articleAjax')}", {start: nStart},function(res) {
$.each(res['result'],function(i, item) {
_this.before('

'+item.goods_title+'
'+item.goods_title2+'
起拍价:¥'+item.start_price+'
倒计时
');
});
});
nStart += 5;
}
});
问题就出在js中
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
js的ajax。你获取到的数据会在res里面。然后你遍历res['result']。你的判断肯定是js的判断方式啊。三目运算符会吧。?:
有多个值需要判断的情况下
有多个值需要判断的情况下,改成function