How to select the option values from the dynamic value


Topic: How to select the option values from the dynamic value
Hi, I am using materialize design. I have two methods from one method dynamic data bind with the option and from second method some values comes in the array and these values selected from the option and show to the user. I am using multiple attribute with select. But, the dynamically values bind with the option but it's not selected. The code is here. I am using the Meteor Framework. Helpers: bindDataWithOption: function() { return Session.get('workType'); } 'click .updateJobOrder': function(event, templateInstance) { Meteor.call('fetchWorkType', function(error, workTypeResponse) { if(workTypeResponse && workTypeResponse.length > 0) { Session.set('workType',workTypeResponse); } }); Meteor.call("fetchJobData', $(event.target).attr("jobId"), function(error, response) { if(response) { //but this line is not working. $(event.currentTarget).parent().parent().next().find("#editworkType").val(response.workType);   } }); } I want that HTML: <select name="workType" multiple id="editworkType"> <option value="" disabled selected>Select Work Type</option> <option value="Others">Others</option> {{#eachbindDataWithOption}} <option value="{{this.work_type}}"> {{this.work_type}}</option> {{/each}} </select> <label>Work Type</label>   I want that fetchJobData method call and get the response and the response comes in the array. That response values selected and show to the user.   Please let me know where I am doing wrong.

Jakub Strebeyko staff answered 6 years ago

Hi there Kunal Differential Edge, Well, for every change in the select it must be re-initialized with
$('.editworkType').material_select();
Only this way it will get populated with dynamically fetched content. Best, Kuba
Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: Other
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No