json - How do I give my javascript anonymous type, property names with incremented counters? -
json - How do I give my javascript anonymous type, property names with incremented counters? -
so here scenario, "serializing" json info anonymous types in javascript post mvc controller. maybe approaching problem in wrong way, have list of objects or array of objects in nested object. below sample of info posting back.
var items = []; var counter = 0; $("#table > tbody > tr").each(function () { var modelid = $(this).find("#models option:selected").val(); var attrib1 = $(this).find("#attrib1 option:selected").val(); var attrib2 = $(this).find("#attrib2 option:selected").val(); var cost = $(this).find("#price").val(); var notes = $(this).find("#notes").val(); var modelname = "myobjects[" + counter + "].modelid"; var attrib1name = "myobjects[" + counter + "].attrib1"; var attrib2name = "myobjects[" + counter + "].attrib2"; var pricename = "myobjects[" + counter + "].price"; var notesname = "myobjects[" + counter + "].notes"; var item = { modelname: modelid, attrib1name: attrib1, attrib2name: attrib2, pricename: price, notesname: notes } items.push(item); counter++; }); tried in couple different ways (laughs accepted) :). need property name value of variable e.g modelname.
any help appreciated!
thanks, steven
javascript json anonymous-types
Comments
Post a Comment