有以下 MongoDB 集合:
{
"_id": "u3Yv2bm4cpsssLSHv",
"allowed": 1,
"country_name": "Canada",
"states": [
{
"state_name": "Alberta"
},
{
"state_name": "British Columbia"
},
{
"state_name": "Manitoba"
},
{
"state_name": "New Brunswick"
},
{
"state_name": "Newfoundland and Labrador"
},
{
"state_name": "Nova Scotia"
},
{
"state_name": "Ontario"
},
{
"state_name": "Prince Edward Island"
},
{
"state_name": "Quebec"
},
{
"state_name": "Saskatchewan"
},
{
"state_name": "Northwest Territories"
},
{
"state_name": "Nunavut"
},
{
"state_name": "Yukon"
}
]
}
如何返回此集合中“状态”的值,以便填充下拉列表?我正在尝试执行以下操作(在“状态”子文档中不返回任何内容):
venue_province: {
type: String,
label: "Province/State",
optional: true,
max: 200,
autoform: {
type: 'chained',
// Gets a list of province/state names from the locations collection
options: function() {
return _.map(bt_col_locations.find().fetch(), function(item) {
return {value: item.states.state_name, label: item.states.state_name, parent: item.country_name}
})
}
}
请注意,我使用的是 Aldeed:Autoforms 和 jQuery Chained;基本上我有一个父下拉列表供用户选择国家,子下拉列表与相应的州/省级联。