Set the selected item in a select list based on template value

后端 未结 5 1763
生来不讨喜
生来不讨喜 2020-12-14 21:23

How can you correctly pre-populate a select control with the current value from the template?

I have a simple form to edit a record where the values for the selected

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-14 21:45

    I made this function. Adapt to your case

    selectedOption=function(){
            selectedOpt=document.getElementById("yourTagId_Select");
            var att = document.createAttribute("selected");
            att.value = "selected";
            idObj=Session.get("idObj");
            var lib = yourCollection.find({'column._id':idObj}).fetch();      
            for (var i = 0; i < selectedOpt.length; i++) {
                 if (selectedOpt[i].value==lib._id._str){               
                    return selectedOpt[i].setAttributeNode(att);
                }
            };
    
    
        }
    

    After call your function

    selectedOption();

提交回复
热议问题