1

angular-ui からselect2を使用します。すべて正常に動作しますが、ng-model オブジェクトに渡され、単純な値を取得する必要があります

これはコントローラーにあります

$scope.units = {
            createSearchChoice:function(term, data) {
                if ($(data).filter(function() {
                    return this.text.localeCompare(term) === 0; }).length===0) {
                    return {id:term, text:term};
                }
            },
            multiple: false,
            data: [{id: 0, text: 'kg'},{id: 1, text: 'ks'},{id: 2, text: 'm'}, {id: 3, text: 'h'}]
        }; 

そしてこれを視野に

<input type="hidden" class="form-control" id="unit_name" ui-select2="units" ng-model="newItem.unit">

しかし、結果は {id: 0, text: 'kg'} であり、そのオブジェクトからのテキストのみが必要です。.val() で取得できることはわかっていますが、angular では使用できません...出力をフォーマットするにはどうすればよいですか? 出来ますか?ありがとう

4

1 に答える 1

1

私もこの問題を抱えており、からいくつかのコード行を削除することで解決しましたselect2-ui.js

select2-ui.js のコードに続くコメント

elm.bind("change", function(e) {
   e.stopImmediatePropagation();
   if (scope.$$phase || scope.$root.$$phase) {
      return;
   }
   scope.$apply(function() {
      controller.$setViewValue(
      convertToAngularModel(elm.select2('data')));
   });
}); 
于 2014-09-08T10:36:28.393 に答える