检测[i]值
我试图建立一个条件,其中 [i] 是 data.length 的值,问题是当有超过 1 个值时一切正常,但当只有 1 个值时,脚本不起作用。
out.href = data[i].href;
out.innerHTML = data[i].alt;
out.appendChild(document.createElement('br'));
}
}
解释: 当data.length大于1时,结果将是object1.href、object2.href等。 但是当返回的查询只有 1 个值时,我希望它只写“object.href”,而不包含其中的 [i],因为这适用于 yql,并且当 yql 仅返回 1 个对象时,对象编号是直接的,而不是有任何价值。而不是 object1.href,只会有 object.href,但脚本不断将值放置在 object[i].href 中,因此当仅返回 1 个结果时会失败。
有没有 if...else 方法?
I am trying to make a condition where [i] is a value for data.length, the problem is that everything works okay when there are more than 1 value, but when theres only 1 value, the script doesnt work.
out.href = data[i].href;
out.innerHTML = data[i].alt;
out.appendChild(document.createElement('br'));
}
}
Explanation:
When data.length is more than 1, the result will be object1.href, object2.href, etc.
But when the returned query is only of 1 value, i want it to write just "object.href" without the [i] in it, because this works with yql and when yql returns only 1 object, the object number is direct, doesnt have any value. Instead of object1.href, there will only be object.href but the script keeps placing the value in object[i].href thus failing when only 1 result is returned.
Is there any if...else method for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查每个 YQL 响应返回的
count
值。Check the
count
value which is returned with every YQL response.