0

我创建了一个自定义模板,使用 ui-select 来标记输入:

formlyConfig.setType({
        name: 'ui-tagging',
        extends: 'select',
        template: '<ui-select multiple tagging="" tagging-label="(\'new\')" ng-model="model[options.key]" theme="bootstrap" ng-required="{{to.required}}" ng-disabled="{{to.disabled}}"> <ui-select-match placeholder="{{to.placeholder}}"> {{$select.selected[to.labelProp || \'name\']}} </ui-select-match> <ui-select-choices repeat="option in to.options | filter: $select.search"> <div ng-bind-html="option | highlight: $select.search"></div> </ui-select-choices> </ui-select>',
    });

这是问题所在,我想设置一个函数来进行属性标记以转换标签,例如 ui-select 文档中的示例。

<ui-select tagging="tagTransform" .....

带有 ui-select 示例的 Plunker:http ://plnkr.co/edit/m1SQXUxftBLQtitng1f0?p=preview

4

1 回答 1

1

为此,您只需在字段选项上引用一个函数。像:(options.templateOptions.tagTransform它有一个快捷方式:)to.tagTransform。所以你可以有类似的东西:

formlyConfig.setType({
        name: 'ui-tagging',
        extends: 'select',
        template: '<ui-select multiple tagging="to.tagTransform()" tagging-label="(\'new\')" ng-model="model[options.key]" theme="bootstrap" ng-required="{{to.required}}" ng-disabled="{{to.disabled}}"> <ui-select-match placeholder="{{to.placeholder}}"> {{$select.selected[to.labelProp || \'name\']}} </ui-select-match> <ui-select-choices repeat="option in to.options | filter: $select.search"> <div ng-bind-html="option | highlight: $select.search"></div> </ui-select-choices> </ui-select>',
    });

字段配置类似于:

{
  type: 'ui-tagging',
  templateOptions: {
    tagTransform: function() {}
  }
}
于 2015-10-02T22:23:06.070 回答