【问题标题】:Using Angular Bootstrap Typeahead. Trying to get value of json different than value shown使用 Angular Bootstrap Typeahead。试图让 json 的值与显示的值不同
【发布时间】:2014-09-07 23:35:35
【问题描述】:

我有一个 json 对象

states = { id:1, name: "Sales Manager" }

我有一个预先输入的输入

<input type="text" 
       placeholder="Position" 
       ng-model="position" 
       typeahead="title.name for title in states($viewValue)" />

当我选择是否使用 name 变量时,这很好,但我需要使用从 json 中选择的 id 值设置隐藏输入。有什么办法吗?

【问题讨论】:

    标签: json angularjs bootstrap-typeahead


    【解决方案1】:

    我可能会解决这个问题的一种方法,在您的控制器中在 position 上设置一个手表:

    $scope.$watch('position', function() {
      selectedPositionId = getIdForPositionName($scope.position);
    });
    

    这样selectedPositionId 将始终是用户选择的position 的值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多