1

每次我向 ui-select2 输入添加新值时,它都会再次编译所有选择。我该如何防止呢?我想添加一个指令,这可能很重。

谢谢!

看看这个plunker只需添加一个新项目,因为所有值都在变化。

我的输入在指令中:

app.directive('optionChoices', function () {
  return {
    restrict: 'EA',
    scope: {
      option: '='
    },
    template: '<input ui-select2="colorChoices" ng-model="option.selections" style="width:200px">',
    controller: ['$scope', '$compile', function ($scope, $compile) {

    function Query(query) {
        var data = query.term !== ''?
        { results:[{id : query.term, value: '', text : query.term}] } :
        { results:[] };
        query.callback (data);
    }

    function colorFormat(state, container) {
        return (new Date().getTime() / 1000);
    }

    $scope.textChoices = {
        query: Query,
        initSelection: angular.noop,
        tags: []
    };
    $scope.colorChoices = angular.extend({}, $scope.textChoices, {
        formatSelection: colorFormat
    });
    }]
  };
});
4

0 回答 0