Conditional mappings when looping over list items when invoking services?
I'm building a UI where I want to enable the user to select from a bunch of options, and save the selected items into a database. What's the best way to go about this? I'm right now trying to use jQuery selectors to pick out the questions from the list, and finding that there are a LOT of wrappers in the generated HTML code, so it's leading to rather convoluted selector (the way it's looking, it's going to be a series of nested selectors + loops, some pretty ridiculous code).
This is of course compounded by the fact that the editor has no introspection, so the only way to test the selector is to save the script + fire off a test, which is clunky.
So I'm wondering, is this the best way to go about this? I'm not even finding the IDs for the options I need to save, which would be problematic; I need those in order to save pointers. If there's a cleaner way to get this code in there, please let me know.
I haven't found a good way of looping over a set of options to build mappings, either. I can create a single mapping for each one when there' s a preset number of them (I know this isn't good engineering, but I haven't a better way to do this yet)... that doesn't work when the number of items to save is dynamic.
So, is there a way to create a pre-execute mapping for a service that loops over the items in a list, and performs the mapping + executes them depending on a condition? If that condition isn't met, skip that list entry and move on to the next one?
Thanks!