Adding jQuery Drop Downs to a Variable Length Data Entry Page

爱⌒轻易说出口 提交于 2019-12-04 22:03:36

Best thing I can recommend, grab a common parent for a single row and use that as a reference point throughout the rest of the row. (if these are <tr>'s of a table, label the tr or give it a class you can use to call it with). When you need to change something else in the row, use .closest to find the parent, then traverse back down to the field you desire.

Next, unless this data is truly dynamic, try caching the results of the drop-down in a local variable that you can use with each new row. That is to say, if there are always the same entries (retrieved via ajax) for request type and use hours type, just re-populate it from var request_types and var use_hours_types.

Third, look in to using .live as this will bind to the DOM elements despite changes made to it after the initial binding. So if your second part of the row is based on a selection of the drop down, use something like:

$('dropdown').live('change',function(){
   $(this).close('parent_object').filter('.corresponding_row').show();
});

(or some facsimile).

Without seeing the code you have in place, just think about a different approach to how you gather the information. The tough part is you don't want to do a broad re-assignment of each drop-down with the ajax data (presumably) as this would effect current selections. So whenever possible save the data and use it when you create a new row.

Mike Wills

I have a start of a solution over at this question.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!