在我的 js 函数中,我有以下内容
success: function (result) {
$.each(result, function (i, item) {
$("#tab-" + item.myType).append(result);
})
}
现在我已经更改了这个函数,而是有以下内容
success: function (result) {
$("#tab-how To Access to the first result collection element ").html(result);
}
}
我尝试过
$("#tab-" + result[0].item.myType).html(result);
但这并没有帮助。
问题是:如何访问结果集合对象中的第一个js元素
有什么想法吗?
使用 console.log(result) 我得到了在部分 View 上显示的 html 片段
div class="product clearfix">
<div class="l-new">
<a href="#">
@Model.MyType (rendered as My Type)
</a>
....
</div>
最佳答案
你可以尝试:
result[0] // if you have numeric indices in your result collection
或者
var firstItem = null;
for(var x in result) { // if you have named properties
firstItem = result[x];
break;
}
关于javascript - 访问js集合中的第一个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14056779/