angular - Angular Dragula - 放置时不更新 Firebase
问题描述
我有一个 AngularFireList 项目。
我将项目拆分为数组,并根据每个项目的位置值(对应于 div 的 ID)使用它们为一个 Dragula 袋填充多个 div。
将一个项目放入另一个 div 时,拖动项目的位置值将更新为新 div 的 id。所有这一切都按预期工作,但项目位置值的更新没有保存到 Firebase,所以当我检查项目时,我看到了更新的值,但如果我刷新页面,什么都没有保存。
我哪里出错了?
HTML:
<div
[dragula]='"bag-equipment"'
[dragulaModel]="equipmentArmor"
id="armor"
>
<mat-card *ngFor="let item of equipmentArmor">
{{ item.name }}
</mat-card>
</div>
<div
[dragula]='"bag-equipment"'
[dragulaModel]="equipmentBagOfHolding"
id="bagOfHolding"
>
<mat-card *ngFor="let item of equipmentBagOfHolding">
{{ item.name }}
</mat-card>
</div>
TS:
ngOnInit() {
this.dragula.drop.subscribe(value => {
// Get location item is dragged to
let destination = value[2]['id'];
// Get item's name and clean it up
let itemName = value[1]['innerText'];
itemName = value[1]['innerText'].trim();
itemName = itemName.slice(0, -5);
// Update the FireList's itemList
this.itemList.find(item => item.name == itemName).location = destination;
});
let data = this.itemService.getData();
data.snapshotChanges().subscribe(item => {
this.itemList = [];
item.forEach(element => {
let json = element.payload.toJSON();
json["$key"] = element.key;
this.itemList.push(json as Item);
});
this.itemList = this.itemList.filter(item => item.equippable == true);
this.equipmentArmor = this.itemList.filter(item => item.location == 'armor');
this.equipmentBagOfHolding = this.itemList.filter(item => item.location == 'bagOfHolding');
this.equipmentMisc = this.itemList.filter(item => item.location == 'misc');
this.equipmentWeapons = this.itemList.filter(item => item.location == 'weapons');
});
}
解决方案
我猜 deviceBagOfHolding/this.itemList 与 itemService.getData() 返回的数组不是同一个数组。由于您的 UI 与这些数组相关联,因此当它们更改时,它会更新,但 itemService.getData() 中的数组不会。
推荐阅读
- asp.net - http://localhost:7454/Scripts/bootstrap.min.js 0x800a1391 中的第 21 行第 1 列未处理的异常 - 'jQuery' 未定义
- javascript - 有人可以解释以下java脚本代码吗
- ubuntu - 我如何理解 pthread_create 内存使用情况?
- php - 如何使用 reactphp 编写 php 异步函数
- elixir - `__info__/1` 记录在哪里?
- php - 在 .htaccess 文件 XAMPP Windows 中设置变量
- php - MYSQL 的 BETWEEN 日期的 SQL 查询不包括指定范围?
- ios - 从 iOS 将视频分享到 Instagram 源
- user-interface - Unity3D - “父级有一种布局组”错误
- memory - 静态内存分配的最佳算法