Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正确读取、使用Firebase数据,并使用React Native进行写入_Firebase_React Native_Google Cloud Firestore_React Native Ios_React Native Firebase - Fatal编程技术网

正确读取、使用Firebase数据,并使用React Native进行写入

正确读取、使用Firebase数据,并使用React Native进行写入,firebase,react-native,google-cloud-firestore,react-native-ios,react-native-firebase,Firebase,React Native,Google Cloud Firestore,React Native Ios,React Native Firebase,我正试图利用我的Google firebase来保存设备细节、工作细节和工单等数据。我当时的想法是将它全部保存在firebase firestore上。在react native中,我希望能够使用单独的函数文件访问firebase上的数据,然后对其进行处理,然后在firestore上写入新信息。使用带有push的异步函数在数组中临时保存数据时遇到了一些问题,并且无法定期将这些信息用于各种函数。下面的代码只会导致太多的承诺异常。有没有更好的脚本编写方法?或者,你有没有办法简化这个过程 从'@rea

我正试图利用我的Google firebase来保存设备细节、工作细节和工单等数据。我当时的想法是将它全部保存在firebase firestore上。在react native中,我希望能够使用单独的函数文件访问firebase上的数据,然后对其进行处理,然后在firestore上写入新信息。使用带有push的异步函数在数组中临时保存数据时遇到了一些问题,并且无法定期将这些信息用于各种函数。下面的代码只会导致太多的承诺异常。有没有更好的脚本编写方法?或者,你有没有办法简化这个过程

从'@react native firebase/firestore'导入firestore';
班主任{
建造商(名称、证书、班次、位置){
this.name=名称;
此项。认证=认证;
this.shift=shift;
这个位置=位置;
此.currentPosition=位置;
此.timeLeftinShift=8;
本附表=[];
this.doneScheduling=false;
}
}
班工单{
建造师(
开斋节,
词缀,
设施,
位置,
优先,
时间戳,
完成时间,
) {
this.eID=eID;
this.eType=eType;
这个。设施=设施;
这个位置=位置;
优先权=优先权;
this.timeStamp=时间戳;
this.timeToComplete=timeToComplete;
this.done=false;
}
}
班级设施{
建造商(名称、位置、maxOcc){
this.name=名称;
这个位置=位置;
this.maxOcc=maxOcc;
这个.curOcc=0;
}
}
//指派一名工人
导出函数assignWorker(){
var tempWorkers=[];
异步函数工人(){
const workersCollection=wait firestore()
.collection(“workers”)
.get()
.然后(异步(querySnapshot)=>{
querySnapshot.forEach(异步(文档快照)=>{
let temp=新员工(
documentSnapshot.id,
documentSnapshot.data()证书,
documentSnapshot.data().Shift,
[
documentSnapshot.data().Location.longitude,
documentSnapshot.data().Location.latitude,
],
);
临时工人。推(临时);
});
});
返回工人;
}
var tempFacilities=[];
异步函数设施(){
var tempFacilities=[];
const facilitiesCollection=wait firestore()
.collection(“设施”)
.get()
.然后(异步(querySnapshot)=>{
querySnapshot.forEach(异步(文档快照)=>{
let temp=新设施(
documentSnapshot.id,
[
documentSnapshot.data().Location.longitude,
documentSnapshot.data().Location.latitude,
],
documentSnapshot.data()[“最大占用率”],
);
临时设施。推送(临时);
});
});
归还设施;
}
var tempWorkOrders=[];
异步函数workOrders(){
var tempWorkOrders=[];
const workOrdersCollection=wait firestore()
.collection(“工作单样本”)
.get()
.然后(异步(querySnapshot)=>{
querySnapshot.forEach(异步(文档快照)=>{
let temp=新工作订单(
documentSnapshot.data()['Equipment ID'],
documentSnapshot.data()[“设备类型”],
documentSnapshot.data()工具,
getFCoord(documentSnapshot.data().Facility,TempFacility),
documentSnapshot.data()['Priority(1-5)',
documentSnapshot.data()['Submission Timestamp'],
documentSnapshot.data()[“完成时间”],
);
临时工单推送(临时);
});
});
返回临时工单;
}
//最后部分
console.log(“已达到指定的时间表”);
工作顺序()。然后((y)=>{
工人()。然后((z)=>{
转让附表(z,y);
对于(设i=0;i{});
}
});
});
console.log(“已达到指定的时间表”);
函数getFCoord(初始值){
设施()。然后((x)=>{
对于(设i=0;i()
//按可以完成任务的工作人员筛选每个任务
//对于每个工作人员,筛选他们可以完成的任务
//紧急度得分将是优先级和时间的函数,因为任务已被请求