javascript - 将对象更新为新对象的实例
问题描述
在 Angular/typescript 中,是否可以将列表中的对象实例更新为新对象,并将更改显示在 .html 上的绑定列表中?
- 我得到一副纸牌。
- 我画了三张卡片(以 HTML 显示)
- 绘制一张卡片并将列表中的第一张卡片更新为已绘制的新卡片,但它没有在 HTML 中更新,即使我查看数据已更新的对象也是如此。
代码:
// this works
this.Items[0] = this.Items[1]
//this does NOT work.
let newItem = new Item();
newItem.Id = x;
this.Items[0] = newItem;
draw(deckId: string, count: number): Observable<Deck> {
return this.http.get<Deck>(url).pipe(catchError(this.handleError));
}
drawThreeCards() {
this.deckService.draw(this.deck.deck_id, 3).subscribe(data => {
this.cards = data;
}
drawOneCards() {
this.deckService.draw(this.deck.deck_id, 1).subscribe(data => {
// Just as test I want to set the first card in the current
// this.cards to the new card drawn
let match = this.cards.find(x => x.Id == this.Items[0].code);
match = this.data;
}
解决方案
推荐阅读
- swift - Swift 5,无法显示此文本
- python - 如何在 Python、Sqlite3 中处理日期。日期存储为 vachar?
- jhipster - 来自 OAuth 提供者的用户数据不匹配
- wordpress - 如何在 Polylang 插件的特定页面中隐藏语言代码
- reactjs - Mapbox GL Js,动态改变地图容器大小,无法调整地图大小
- file - 编辑没有扩展名格式的文件(二进制 vs gbrish)
- django - 即使模块就位,模块未找到错误
- azure-functions - 是否有重播 Azure 队列存储消息的模式?
- json - Python循环遍历json数组值错误
- python - 使用索引根据另一个数据帧上的值替换数据帧上的值