Themes[0].Subject is the actual name ... It is so to be read by an MVS framework into a List.
Basically when the page loads some items are already there rendered on the server. They are always with the correct order. However, when I add / remove items to that list the order might change ... So I should add and remove all items? How can I do this? And why? I am posting my entire code: // Cancel button $('#Cancel').click(function() { location.href = '/Account/ List'; }); // Themes >> // Remove theme $('.Remove').livequery('click', function(event) { $(this).parent().remove(); }); // Add theme $('#AddTheme').bind('click', function(){ // Define index $index = $('#Index'); // Set valid var valid = new Boolean(true); // Define fields $description = $('#Description'); $levels = $('input[name="Levels"]:checked + label'); $levelsTypes = $('input[name="Levels"]:checked'); $subject = $('#Subject option:selected'); // Map levels levels = $levels.map(function() { return $(this).text(); }).get (); levelsTypes = $levelsTypes.map(function() { return $(this).val (); }).get(); // Validate if (!$subject.val()) { valid = false; } if (!levels.length) { valid = false; } // Validate if (valid) { // Define theme $theme = $('<li class="Themes"></li>').appendTo ('#ThemesOnTutor'); // Add fields $theme.append($subject.text()).append('<br />'); $theme.append(FriendlyLevels(levels) + '<br />'); if ($description.val()) {$theme.append($description.val ()).append('<br />');} // Add button $theme.append('<a href="#Remove" class="Remove">Remover</ a>'); // Add inputs $theme.append('<input type="hidden" name="Themes.Index" value = "' + $index.val() + '" />'); $theme.append('<input type="hidden" name="Themes[' + $index.val() + '].Subject" value = "' + $subject.val() + '" />'); $theme.append('<input type="hidden" name="Themes[' + $index.val() + '].LevelsCsv" value = "' + levelsTypes.join(",") + '" / >'); $theme.append('<input type="hidden" name="Themes[' + $index.val() + '].Description" value = "' + $description.val() + '" / >'); // Increment index $index.val(+$index.val() + 1); } }); // FriendlyLevels function FriendlyLevels(levels) { if (levels.length < 2) return levels.join(''); var first = levels.slice(0, -1), last = levels.slice(-1); var friendly = first.join(', '); if (last) { friendly += ' e ' + last; } return friendly; } // FriendlyLevels On Feb 11, 9:47 pm, seasoup <seas...@gmail.com> wrote: > You could remove the entire list everytime and regenerate it from > javascript. Is Themes[0].Subject the actual name, or are you trying > to refer to a javascript object in an array with the attribute > 'Subject' which contains the name you are looking for? If it is the > latter, this won't work. you'll need to create the html in javascript > and append it into the page. > > $('<li><input type="hidden" name="' + Themes[0].Subject + '" > value="A"></li>').appendTo($('#ThemesList')); > > I'm actually not sure if jQuery handles appending a list item to a > list properly. Probaby does. > > On Feb 11, 1:19 pm, shapper <mdmo...@gmail.com> wrote: > > > Hello, > > > I am adding and removing a items from a list, using JQuery, which is > > rendered has follows: > > > <ol id="ThemesList"> > > <li"> > > <input type="hidden" name="Themes[0].Subject" value="A" /> > > <input type="hidden" name="Themes[0].Levels" value="L1,L2" /> > > <input type="hidden" name="Themes[0].Description" value="Paper" /> > > </li> > > <li"> > > <input type="hidden" name="Themes[2].Subject" value="B" /> > > <input type="hidden" name="Themes[2].Levels" value="L1,L5" /> > > </li> > > <li"> > > <input type="hidden" name="Themes[5].Subject" value="D" /> > > <input type="hidden" name="Themes[5].Levels" value="L2,L4" /> > > <input type="hidden" name="Themes[5].Description" value="Book" /> > > </li> > > </ol> > > > Every time I add or remove a Theme I need to be sure that the list is > > ordered (name) starting with Themes[0]. > > > So basically I need to loop through each list item in list ThemesList. > > - In first list item all HIDDEN inputs names should start with "Themes > > [0]" > > - In second list item all HIDDEN inputs names should start with "Themes > > [1]" > > ... > > > So in this example, "Themes[2]. ..." would become "Themes[1]. ..." and > > "Themes[5]. ..." would become "Themes[2]. ..." > > > Could someone please help me out? > > > I have no idea how to do this. > > > Thanks, > > Miguel