Jquery Chosen plugin - dynamically populate list by Ajax

后端 未结 12 1032
野性不改
野性不改 2020-12-04 11:14

Im trying to build my dropdown menu using the plugin Chosen for Multiple Select . Here\'s to behavior I\'m based on:

http://jsfiddle.net/JfLvA/

12条回答
  •  春和景丽
    2020-12-04 11:54

    The Chosen plugin does not automatically update its list of options when the OPTION elements in the DOM change. You have to send it an event to trigger the update:

    Pre Chosen 1.0: $('.chzn-select').trigger("liszt:updated");

    Chosen 1.0 $('.chosen-select').trigger("chosen:updated");

    If you are dynamically managing the OPTION elements, then you'll have to do this whenever the OPTIONs change. The way you do this will vary - in AngularJS, try something like this:

    $scope.$watch(
      function() {
        return element.find('option').map(function() { return this.value }).get().join();
      }, 
      function() {
        element.trigger('liszt:updated');
      }
     }
    

提交回复
热议问题