typescript - Typescript .then() 函数没有为变量赋值
问题描述
我有以下代码:
var roomStatementToBeCreated = new RoomStatement();
var roomId = this.bookingRequest.roomDetails.allocations[0].roomId;
this.roomService.get(roomId).then((room) => {
roomStatementToBeCreated.buildingId = +room.building.id_original;
roomStatementToBeCreated.roomTypeId = +room.roomType.id_original;
roomStatementToBeCreated.roomNumber = +room.id_original;
});
在 .then() 中,所有变量都获得了它们的值。但是,之后它必须保存在数据库中,并且保存为 0 值。并且在调试时它说离开 .then() 后它们具有未定义的值。
我认为这个问题与范围有关,但是我不确定 roomStatementToBeCreated.buildingId 和其他人如何将它们的值保存在 .then() 之外。
解决方案
推荐阅读
- css - 不能为 css-houdini 绘画做 JS-in-CSS 吗?
- excel - 如何在 Excel 中的 MMULT 查找中找到最后一个匹配项?
- node.js - 有人如何处理 webpack 版本问题«需要...但没有安装的对等»?
- php - 如何通过更改 sql 请求的偏移值来显示更多帖子?
- vb.net - 在 VB.NET 中使用 HtmlAgilityPack.HtmlDocument 向下钻取
- node.js - 为什么我的 heroku 工人 dyno 不工作?
- php - 您如何每周显示数据,不仅是本月的数据,而是用户的全部数据
- arrays - while ((*s = *t) != '\0') 是什么意思?
- javascript - 如何在 Web Animation API 中反转无限动画?
- javascript - 尚未为模型“产品”注册架构