How to fix IE select issue when dynamically changing options

前端 未结 13 536
南旧
南旧 2020-12-04 16:38

I have a set of selects that all have the same options. Then I run those options through a filter so that any options that are selected in a different select don\'t show up

13条回答
  •  旧巷少年郎
    2020-12-04 16:49

    I've finally come up with a solution that works for my needs. Basically what appears to be happening is that the text for the option at the selected index is pointing to the old string that used to be in that place. I believe changing this text updates the strings and/or references. I did something like this:

    angular.forEach($("select"), function (currSelect) {
         currSelect.options[currSelect.selectedIndex].text += " ";
    });
    

    Here is the updated fiddle: http://jsfiddle.net/H48sP/35/

    In my app, I have a directive where these selects are, and so I do element.find("select") instead of $("select") to limit the scope of the element selecting. The text is forced to refresh and so displays correctly after all the digest cycles run.

    If you have run into this same issue, you may need to add a $timeout like in the fiddle, and/or you may need to later remove the extra space that was added to the option text if that becomes a problem.

提交回复
热议问题