2

私の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)を使用して、部分ビューで表示するhtmlスニペットを取得しています

div class="product clearfix">
        <div class="l-new">
            <a href="#">
                @Model.MyType (rendered as My Type)
            </a> 
....
</div>
4

1 に答える 1

2

あなたが試すことができます:

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;
}
于 2012-12-27T15:12:14.373 に答える