';加入';angularjs中的两个模型

';加入';angularjs中的两个模型,angularjs,Angularjs,我有一个显示可编辑值的表单。其中一个值是用户的id。我不想显示要显示用户名的用户的id 我这样做,效果很好: <div class="control-group"> <label class="control-label" for="type">Point of Contact</label> <div class="controls"> <select ng-model="device.poc

我有一个显示可编辑值的表单。其中一个值是用户的id。我不想显示要显示用户名的用户的id

我这样做,效果很好:

    <div class="control-group">
      <label class="control-label" for="type">Point of Contact</label>
      <div class="controls">
        <select ng-model="device.poc" ng-options="user._id as user.username for user in users">
        </select>
      </div>

接触点
现在,我试图以不可编辑的形式显示所有设备的列表,以便使用ng REPECT循环设备

<div ng-repeat="device in devices | filter:{registered: true}" class="top-gap">
     <div class="row">
        <div class="span2">
          {{device.name}}
        </div>
        <div class="span2">
          {{device.poc}}
        </div>
      </div>

{{device.name}
{{device.poc}

但是device.poc不是我想要显示的,我想要显示附加到该设备的用户名。在mustaches“{{}”中,我可以像在select中那样“加入”到用户模型中,以便显示用户名吗?

如果希望device.poc属性保存用户对象,请将ng选项更改为:

user.username for user in users
那你应该能做到

{{device.poc.username}}

在需要id的地方,device.poc.\u id

为什么不简单地向控制器作用域添加一个函数
getUserById()
,您可以使用
{getUserById(device.poc.username}}
调用它呢?或者在获取设备时遍历这些设备,并在每个设备中添加一个用户对象,以便能够使用
{{device.user.username}
?哦,对不起,ng选项已经起作用了,请重新阅读问题。我希望在选择框之外使用这种类型的功能。如果将device.poc设置为您的用户对象,那么我想我不确定问题出在哪里。如果您要求将device.poc仅设置为用户的id,那么您将需要一个查找函数,如JB Nizet建议的。正确,我需要一个查找函数。虽然我不支持select,但我想确保我没有遗漏什么。select使用ng options指令通过特定的表达式语法声明后台查找函数。{{}语法用于泛型表达式求值,因此需要提供自己的查找方法。