Display value of an object item using Javascript

Asked

Viewed 93 times

0

I’m a beginner in Javascript, I don’t know how to display the value qtdeEstoque of listaTamanhos. Can someone help me?

alert("Tamanho: " + lista.Value + " / Estoque: " + data[i].qtdeEstoque);

listings:

id
qtdeEstoque

Controller:

if (HttpContext.Request.IsAjaxRequest())
{
    return Json(new SelectList(
                listaTamanhos,
                "id",
                "id"), JsonRequestBehavior.AllowGet
                );
}

View:

$.getJSON("/produto", { id: id, cor: idSelected }, function (data) {
   $.each(data, function (i, lista) {
      alert("Tamanho: " + lista.Value + " / Estoque: " + data[i].qtdeEstoque);
   });
});
  • view where? you already have some table and want to fill it? you want to create one from scratch?

  • Guilherme, I would like to display the qtyThis message in a Javascript message. It is in a list, already comes from the table.

  • var listTamanhos = size.Listbyproduct(id); I don’t know how to access the qtyThis attribute is from this list in Javascript. I am returning via Json Return Json(new Selectlist( listSize, "id", "id"), Jsonrequestbehavior.Allowget );

  • Note that you are with (new SelectList(listaTamanhos, "id", "id"), JsonRequestBehavior.AllowGet); would not be (new SelectList(listaTamanhos, "id", "qtyTech" ), JsonRequestBehavior.AllowGet);?

  • You came to debug and see if there is data[i].qtdeEstoque because for what you said no.

  • would not be, return (new Selectlist(listTamanhos, "id", "id"), Jsonrequestbehavior.Allowget), because I will mount in html a select in html. And the ID is the value that is the same as the DESCRIPTION. See: <select id="size" class="input-validation-error" data-val="true" data-val-required="Select the size" name="size"> <option value=""">-Select the size-</option> <option value="35/36" >35/36</option> <option value="37/38" >37/38</option> <option value="39/40" >39/40</option> </sel

  • need to access the first parameter of the Selectlist method(listTexts, "id", "id").... listTexts that have the qtyText attribute

  • in Visual Studio I don’t know how to debug Javascript code, only in Controller and View C#codes. I saw in debug that the attribute qtyText of the listTexts is being filled correctly in the Controller. Now I am missing in Javascript. Only I need that code I posted.

Show 3 more comments

1 answer

0

$.getJSON("/produto", { id: id, cor: idSelected }, function (data) {
   $.each(data, function (i, lista) {
      alert("Tamanho: " + lista["id"]+ " / Estoque: " + lista["qtdeEstoque"];
   });
});
  • Pedro, I did so but it didn’t work. Returns "Undefined".. Now, doing so Alert("Size: " + list.Value + " / Stock: " + list["qtyStock"]); Size returns correct and stock "Undefined"

  • Hand me the json

  • var listSize = size.Listings(id); if (Httpcontext.Request.Isajaxrequest()) { Return Json(new Selectlist( listSize, "id", "id"), Jsonrequestbehavior.Allowget ); }

Browser other questions tagged

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