我在从下拉列表中获取值时遇到问题。我有以下结构:
$scope.categories = [
{id: 7, title: 'Peanut Butter'},
{id: 4, title: 'Mustard'},
{id: 3, title: 'Jelly'},
{id: 2, title: 'Jam'},
{id: 1, title: 'Mint Jelly'}
];
我正在创建一个下拉列表,如下所示:
<select class="form-control" ng-model="testme.id" ng-options="c as c.title for c in categories track by c.id">
<option value="">------</option>
</select>
<input type="text" ng-model="testme.pos" />
The dropdown generates fine
例如,如果我在“ testme.pos”中输入“ 3”并选择“ Jam”,但是模型“ testme”附带以下示例结果:
{id: {id: 2, title: 'Jam'}, pos: 3 },
我想看的东西
{id: 2, pos: 3}
任何帮助都会很棒。我创建了一个plnkr:Select Help
答案 0 :(得分:0)
使用ng-model="testme.id"
代替ng-model="testme"