jQuery $.each() - Array of Objects

前端 未结 4 1682
野性不改
野性不改 2021-02-15 00:07

I am trying to perform jQuery each function on something like:

\"RelatedDoc\": [
    {
        \"Id\": \"test\",
        \"Number\": \"26262316\"
    }
],
         


        
4条回答
  •  不思量自难忘°
    2021-02-15 00:47

    option 1 (this uses the key as the option 'id' i.e. 1, 2, 3 etc):

    $.each($('#panel_MRD').data('obj'), function (key,value) {
        $('select.mrdDisplayBox').addOption(key, value.Id + ' - ' + value.Number, false);
    });
    

    have not tested, so potentially rushed answer.

    [edit] - had a quick look back at this as i realised that there are potentially 2 values that you could use as the option 'id', either key or value.Number.

    option 2 (this uses value.Number as the option 'id' i.e. 26262316):

    $.each($('#panel_MRD').data('obj'), function (key,value) {
        $('select.mrdDisplayBox').addOption(value.Number, value.Id + ' - ' + value.Number, false);
    });
    

    will stop thinking now... :-)

提交回复
热议问题