javascript - Nested collection-Form, append to nearest class -
hello have been trying make dynamic collection can post server, after struggeling found guide; http://jarrettmeyer.com/post/2995732471/nested-collection-models-in-asp-net-mvc-3 great written havent got work needs. works fine exept 1 "little" annoying thing.
first information im trying achive;
my classes looks this; qpack has list of questions question has list alternatives
the interface have created looks this;
and markup.
the "add question"-button works great , markup match, thing dosent work wen click on "add alternative" being added first question. markup fine seen in second picture.
the function responsible append looks this;
function addnestedform(container, counter, ticks, content) { var nextindex = $(container + " " + counter).length; //var nextindex = $(counter).length; // orginal var pattern = new regexp(ticks, "gi"); content = content.replace(pattern, nextindex); $(container).append(content); resetvalidation(); }
i want append relative "alternatives" seems goes first, idea how understand "nearest" alternatives?
when jquery selector specifies id (#
) , there multiple ids in html document have id jquery return first.
you must have way specify "alternatives" uniquely throughout page.
alternatively (pun intended) can create new css class, replace
<div id="alternative" ...
with
<div class="alternative-container" ...
then on action of "add alternative" can
var container = $(this).parents('div.alternative-container:first');
Comments
Post a Comment