jQuery $.each() - Array of Objects

前端 未结 4 1813
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-15 00:21

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

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


        
4条回答
  •  庸人自扰
    2021-02-15 00:49

    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... :-)

提交回复
热议问题