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;

dynamic interface, collection of collections

and markup. 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(); } 

enter image description here

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

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -