Apr 15, 2019 02:33 AM|Madog|LINK
I’m iterating thru an EF model and for each property that is a foreign key, I am building a select/dropdown element, $inputFor, by linking to the FT values thru an Ajax call.
I store the element in an object with the property name being the EF Property name.
storedElements[typeName] = $inputFor
I then add the element to the page. The aim is to reuse the element later in another update dialogue, by just accessing the stored element by property name if it’s there, rather than making another Ajax call.
$inputFor = StoredElements[dbField];
I am deploying the same dropdowns on both a filters and update modal. All I have to do is prefix the name of the Id of $inputFor with either ‘Up’ or ‘Filter’.
The issue is, when I change the Id in the Update dialogue, previously built elements I have added to the filters div, completely disappear from the div, presumably because they've had their Id changed.
I have tried deep cloning StoredElements to a temporary object, through $.extend and the lodash library deepClone, and working with that copy, but the Id of the $inputFor element is changed in the original object regardless.
It appears the stored element in either the original or the deep clone, is the same DOM element, regardless of where it is stored.