Fill a list with Json return

Asked

Viewed 443 times

1

I wanted to fill in a textarea or anything that looks like a list, with the items that the guy selects from a dropdow. So I thought so, but I don’t know how to feed the list...

<textarea cols="1" id="lista">
     <ul>

     </ul>
</textarea>

            <script type="text/javascript">
                $(document).ready(function () {
                    $('#Chamada').change(function () {
                        var id = $(Chamada).val();
                        var url = '@Url.Action("MusicaAdc", "Chamada")';
                        $.post(url, { id: id },
                            function (data) {
                                $('#lista').append('<li>"' + value.Nome + '</li>');
                            });
                    });
                });
            </script>
  • All the data you will add in the list are returned at once in the post, or as the user selects, different calls are being made?

1 answer

2


I don’t know how your json is, but if all the data is returned at once you can use each to go through it and add row by row in the value table you should return the value within each, if it’s a string you only use value to show, if it is an array use value["Name"]

$(document).ready(function () {
     $('#Chamada').change(function () {
          var id = $(Chamada).val();
          var url = '@Url.Action("MusicaAdc", "Chamada")';
          $.post(url, { id: id },
          function (data) {
               $.each(data, function(index, value){
                       $('#lista').append('<li>"' + value["Nome"] + '</li>');
                });
           }
      });
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.