2012-10-24 121 views
1

我想用我的AngularJS基础应用程序的jQueryUI小部件做一些有用的指令。AngularJs + JQueryUI等待响应

其中一个适用于“选择”元素,是确定与指令,但唯一不明白的是这一个:

  1. 当选择列表从Ajax请求填充,如何告诉应用jqueryui部件何时填充数据?假设它是用$手表,但不知道如何。

编辑: 在例子中,我想实现的multiselect plugin指令。 请注意,我正在模拟服务器响应,但将所有内容都设置为超时。

这里是一个code on plunker

+0

你有你正在使用的代码?你想做什么? –

+0

我会把它放在答案 –

回答

0

你需要$看着改变的项目列表中,然后调用上的多选插件refresh ... Here is a plunk that shows the solution

angular.module('myui', []) 
    .directive('qnMultiselect', function() { 
     return { 
      restrict: 'A', 
      require: 'ngModel', 
      link: function(scope, elem, attr) { 
      //set up the plugin. 
      elem.multiselect({ allowClear: false }); 

      //get the source of the ngOptions 
      var parts = attr.ngOptions.split(' '); 
      var source = parts[parts.length - 1]; 

      //watch the options source and refresh the plugin. 
      scope.$watch(source, function(value) { 
       elem.multiselect('refresh'); 
      }); 
      }   
     }; 
    }); 
+0

非常感谢。欣赏。 –