angular - 使用公共参数将 ID 从一个集合拉到另一个集合
问题描述
好的,所以我对 Angular 还很陌生,我的应聘者集合引用了带有 ID 的职位发布集合,
但是如何使用与帖子集合的 id 参数匹配的申请人.post 参数来拉出 postTitle?
两种模式
邮政
var PostSchema = new mongoose.Schema({
category : { type: Schema.Types.ObjectId, ref: 'Category' },
id: String,
postTitle: String,
postAuthor: String,
postDescription: String,
postQualifications: String,
postReference: String,
updated: { type: Date, default: Date.now },
});
申请人
var ApplicantSchema = new mongoose.Schema ({
post : { type: Schema.Types.ObjectId, ref: 'Post' },
id: String,
appName: String,
appPhone: String,
appEmail: String,
appAddress1: String,
appAddress2: String,
appResume: String,
updated: { type: Date, default: Date.now }
});
HTML
<div class="button-row">
<a mat-flat-button color="primary" [routerLink]="['/applicant']">Back</a>
</div>
<hr>
<div class="row application">
<div class="col-md-6">
<h3>{{applicant.appName}}</h3>
<h4>Applying for: {{applicant.post}} || Need post.postTitle </h4>
<h4>Submitted: {{applicant.updated | date: 'dd MMM yyyy'}}</h4>
</div>
<div class="col-md-5">
<h4>{{applicant.appPhone}}</h4>
<h4>{{applicant.appEmail}}</h4>
<h4>{{applicant.appAddress1}}, </h4>
<h4>{{applicant.appAddress2}}</h4>
</div>
<div class="col-md-1">
<a class="btn btn-block" button (click)="deleteApplicant(applicant.id)">
<mat-icon>delete</mat-icon>
</a>
</div>
<br>
<div class="col-md-12">
<p innerHTML={{applicant.appResume}}></p>
</div>
</div>
解决方案
您必须在您的 node.js 应用程序中进行更改,使用 mongoose 人口并在您的路由器文件中填充 Post 模型,您将在其中根据 id 过滤申请人,如下所示:-
Applicant.findOne({id: req.applicant.id})
.populate('post')
.then(res => {// postTitle will be accessible here})
这里申请人是你的模特。
参考猫鼬填充。
推荐阅读
- php - [Route: admin.request.update] [URI: admin/request/{request}] [Missing parameter: request] 缺少必需参数
- laravel - 如何使用 fs 函数?获取 ERROR fs.readFileSync 不是函数
- angular - angular 11 自定义可访问资产文件夹
- python - 从数据框列中删除类似空格+字母+空格的字符串
- java - 使用 Launch4j 将 .jar 转换为 .exe 后调整窗口大小
- android - 在 React Native Android 应用程序中的 Apple 登录失败
- git - 在 git --patch 期间显示当前文件名
- delphi - Delphi 应用程序突然报告 Invalid ImageList
- jakarta-ee - 使用 Microprofile 健康检查时,JobOperator 中没有批处理作业
- wildfly - 如何为 Vaadin 应用程序配置 WildFly 端口