Javascript 对使用填充猫鼬和预填充数据感到困惑
我是一个noob,创建了一个集合-预约-其中有一个字段,名为staff Staff是一个单独的集合,具有id 我试图显示所有约会的列表,并创建一个选择下拉列表,允许我更改工作人员 我很困惑,因为我只是将appoint.staff设置为staff.\u该特定员工的id,但我希望选择下拉列表显示他们的姓名 我想我需要使用“填充”,但由于我是一个noob,我不确定 我该怎么做 这是预约列表的管理员Javascript 对使用填充猫鼬和预填充数据感到困惑,javascript,angularjs,node.js,mongodb,mongoose,Javascript,Angularjs,Node.js,Mongodb,Mongoose,我是一个noob,创建了一个集合-预约-其中有一个字段,名为staff Staff是一个单独的集合,具有id 我试图显示所有约会的列表,并创建一个选择下拉列表,允许我更改工作人员 我很困惑,因为我只是将appoint.staff设置为staff.\u该特定员工的id,但我希望选择下拉列表显示他们的姓名 我想我需要使用“填充”,但由于我是一个noob,我不确定 我该怎么做 这是预约列表的管理员 angular.module('MyApp') .controller('adminController
angular.module('MyApp')
.controller('adminController', ['$scope', 'Appointment', '$state', '$rootScope' , '$stateParams', '$log', '$modal', 'Staff', function($scope, Appointment, $state, $rootScope, $stateParams, $log, $modal, Staff) {
$scope.apps = Appointment.query();
$scope.staffList = Staff.query();
}])
下拉列表的代码:
<td>
<select class="form-control" name="staff"
ng-options="staff._id as staff.name for staff in staffList"
ng-model="app.staff"
ng-change="selectChange(app)"
>
<option></option>
</select>
</td>
员工呢
var mongoose = require('mongoose');
//Creates the appointments Schema for the Staff details
var staffSchema = new mongoose.Schema({
name: String,
email: { type: String, unique: true },
phone: Number,
signup_date: Date,
jobs: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Appointments' }],
total_paid: { type: Number, default: 0 }
});
module.exports = mongoose.model('Staff', staffSchema);
使用staff.name数组代替Appt架构中的staff.ID(因为一个约会中可能有多个员工)
var mongoose = require('mongoose');
//Creates the appointments Schema for the Staff details
var staffSchema = new mongoose.Schema({
name: String,
email: { type: String, unique: true },
phone: Number,
signup_date: Date,
jobs: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Appointments' }],
total_paid: { type: Number, default: 0 }
});
module.exports = mongoose.model('Staff', staffSchema);