我使用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... 那么如何格式化输出呢?可能吗?谢谢