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

后端 未结 5 1752
生来不讨喜
生来不讨喜 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:41

    I used the following in my project (in case someone needs it :)

      
    

    and

    Template.editApplicant.helpers({
       selectedMaritalStatus: function(key){
          return key == this.maritalStatus ? 'selected' : '';
       }
    });
    

    "this.maritalStatus" gets the Marital Status from the current document (Applicant).

    Use the following code, to save the value in the database

    maritalStatus: $('#maritalStatusList').val()
    

    Thanks for you all..

提交回复
热议问题