gpt4 book ai didi

javascript - 加入 AngularFire 2

转载 作者:太空狗 更新时间:2023-10-29 19:34:08 25 4
gpt4 key购买 nike

我见过类似的问题,但这些问题的数据结构与我正在处理的问题略有不同。我看过:

这是我的数据结构:

{
"samples": {
"24084": {
"addInfo": "TEST",
"datePrinted": "8/11/2017 9:42:57 AM",
"equipment": "GR028",
"hmisNumber": "100E",
"lotNumber": "GR0030C659-JM",
"productionNumber": "PN0034781",
"userName": "MCorbett"
},
"24342": {
"addInfo": "test",
"datePrinted": "8/15/2017 11:51:55 AM",
"equipment": "GR025",
"hmisNumber": "100",
"lotNumber": "BR0010P835",
"productionNumber": "PN0035616",
"userName": "MCorbett"
}
},
"scans": {
"-Krlb3tv3oFPtYZp2ErX": {
"inTime": 1502997139131,
"sampleId": "24342"
},
"-KrlbdbCT0us6xE9POm3": {
"inTime": 1502997289573,
"outTime": 1502997292524,
"sampleId": "24342"
},
"-Krlc3vsjiQ9czWYGvA9": {
"inTime": 1502997401784,
"outTime": 1502997404864,
"sampleId": "24084"
}
}
}

如您所见,Samples to Scans 具有一对多关系。我需要做的是填充一个表,其中包含连接到扫描数据的样本数据。它需要看起来像这样:

"24342": {
"addInfo": "test",
"datePrinted": "8/15/2017 11:51:55 AM",
"equipment": "GR025",
"hmisNumber": "100",
"lotNumber": "BR0010P835",
"productionNumber": "PN0035616",
"userName": "MCorbett",
"inTime": 1502996197213
}

我需要获取所有未定义 outTime 的扫描,然后将其加入相应的样本数据。到目前为止,这是我尝试过的:

  // Get samples that have a scan where inTime is populated but outTime is not
getOpenSamples() {
console.log('getopensmaples stareted')
let scanWithSampleList = this.scanSvc.getScansList({
orderBy: 'outTime',
startAt: ''
})
.switchMap(scans => {
let sampleObservables = scans.map(scan => this.getSample(scan.sampleId));
console.log("insisde");
return sampleObservables.length === 0 ?
Observable.of(scans) :
Observable.combineLatest(sampleObservables, (samples) => {
scans.forEach((scan, index) => {
scan.productionNumber = samples[index].productionNumer;
scan.lotNumbner = samples[index].lotNumber;
});
return scans;
});
});
}

这给了我这个错误:

ERROR in C:/Users/corbetmw/workspace/angular/sample-time-tracking/src/app/samples/shared/sample.service.ts (82,54): Propert y 'productionNumer' does not exist on type '{}'.

我在这里做错了什么?这看起来很简单,但我遇到了很多麻烦。我需要更改我的数据结构吗?我是否应该创建一个组件来获取具有未定义 outTime 的扫描,并将其与可以传递样本 ID 的父项一起粘贴在表中,反之亦然?

最佳答案

我找到了一个解决方案,它返回一个 Scan<> 类型的可观察对象用一个Scan在里面。

我有这个功能:

  getOpenScans() {
const scansList = this.db.list('/scans', ref => ref.orderByChild('outTime').endAt(null));
return scansList.snapshotChanges().map(arr => {
return arr.map(snap => Object.assign(snap.payload.val(), {
$key: snap.key
}))
})
}

然后,我有这个人:

  getOpenSamples() {
let openScans = this.scanSvc.getOpenScans();

let fullSamples = openScans.map(scans => {
for (let scan of scans) {
scan.sample = this.getSample(scan.sampleId);
}
return scans;
});

//fullSamples.subscribe(samples => console.log(samples));
return fullSamples;
}

我现在正尝试在 Material2 中使用 MatTable 实现此解决方案。

关于javascript - 加入 AngularFire 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45919716/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com