所以我的问题和这个几乎一样:how to use ng-option to set default value of select element
我无法获得被选中的良好价值。我还尝试了许多使用 ng-init 等的解决方案......
但我不知道如何解决它。
我有这个模型:
var CarSchema = new Schema({
[... some stuff ...]
ville: {
type: Schema.ObjectId,
ref: 'City'
}
});
var CitySchema = new Schema({
name: {
type: String
}
});
我的 HTML 代码:
<select ng-model="car.ville" ng-options="city.name for city in cities"><option value=""/></select>
HERE 1: {{ car.ville | json }}
<BR>
HERE 2 : {{cities | json}}
结果我得到:
HERE 1: { "_id": "536fee62cadf4efc08000001", "name": "Hinsdale" }
HERE 2 : [ { "_id": "53703935cadf4ef008000000", "name": "Noumea" }, { "_id": "536fee62cadf4efc08000001", "name": "Hinsdale" }, { "_id": "536fee3ccadf4ef808000000", "name": "Bascom" } ]
所以我应该选择欣斯代尔市……但不,它在第一行(空行)。
我做错了什么??我尝试了很多配置,但仍然无法正常工作
添加小提琴示例:jsfiddle.net/pL44W/5
所以我让它几乎可以用这个小提琴:
http://jsfiddle.net/Tyvain/UuVYL/
- 可以保存
- 当我们到达页面时,可以检索良好的价值
- NOT OK :当我们在列表中选择时看不到该值。
为了保存,mongo 只需要 ville 属性中的 id。但要显示我需要名称属性...
就像我在绕圈跑...