最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

您能帮我吗?

IT培训 admin 6浏览 0评论

您能帮我吗?

我想使用onUpdate函数在“ front”更新时触发,但是很遗憾,我无法使其正常工作。你能帮我吗?

exports.updateUser = functions.firestore
.document('trashcan/{trashcanId}')
.onUpdate((change, context) => {
  'front';
  // Get an object representing the document
  // e.g. {'name': 'Marie', 'age': 66}
  const newValue = change.after.data();

  // ...or the previous value before this update
  const previousValue = change.before.data();

  // access a particular field as you would any JS property
  const front = newValue.front;

  // perform desired operations ...
回答如下:

您应该在更改前后比较front字段的值,如下所示:

exports.detectFrontChanges = functions.firestore
.document('trashcan/{trashcanId}')
.onUpdate((change, context) => {

  const newValue = change.after.data();
  const previousValue = change.before.data();

  if (newValue.front !== previousValue.front) {
     //front field value has changed
     //Do something

     //e.g. write to the log console
     console.log("front field value has changed!");
     //e.g. and write a Firestore document
     return admin.firestore().collection('events').doc('event1').set({changeType: 'front field'});
  } else {
     //nothing to do
     //return null to indicate to the Cloud Function platform that this Function can be finished
     return null;
  }
}

您能帮我吗?

我想使用onUpdate函数在“ front”更新时触发,但是很遗憾,我无法使其正常工作。你能帮我吗?

exports.updateUser = functions.firestore
.document('trashcan/{trashcanId}')
.onUpdate((change, context) => {
  'front';
  // Get an object representing the document
  // e.g. {'name': 'Marie', 'age': 66}
  const newValue = change.after.data();

  // ...or the previous value before this update
  const previousValue = change.before.data();

  // access a particular field as you would any JS property
  const front = newValue.front;

  // perform desired operations ...
回答如下:

您应该在更改前后比较front字段的值,如下所示:

exports.detectFrontChanges = functions.firestore
.document('trashcan/{trashcanId}')
.onUpdate((change, context) => {

  const newValue = change.after.data();
  const previousValue = change.before.data();

  if (newValue.front !== previousValue.front) {
     //front field value has changed
     //Do something

     //e.g. write to the log console
     console.log("front field value has changed!");
     //e.g. and write a Firestore document
     return admin.firestore().collection('events').doc('event1').set({changeType: 'front field'});
  } else {
     //nothing to do
     //return null to indicate to the Cloud Function platform that this Function can be finished
     return null;
  }
}

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论