小编Ske*_*lly的帖子

如何增加faunadb中的价值?使用 javascript 和服务器端函数

我的 faunadb 数据库中有一个值,我想在单击按钮时将其增加 1。
我不知道该怎么做


我试过这个:

const change = (data) => {
  return fetch(`/.netlify/functions/todos-update`, {
    body: JSON.stringify(data),
    method: 'POST'
  }).then(response => {
    return response.json()
  })
}
Run Code Online (Sandbox Code Playgroud)


并用这个触发它

var dataa = document.getElementById('amount').innerHTML
change(("value: " + dataa))
Run Code Online (Sandbox Code Playgroud)

我的服务器端代码是这样的:

exports.handler = (event, context, callback) => {
  const data = JSON.parse(event.body)
  const id = "236323245287014920"
  console.log(`Function 'todo-update' invoked. update id: ${id}`)
  return client.query(q.Update(q.Ref(`classes/nappi/${id}`), {data}))
    .then((response) => {
      console.log('success', response)
      return callback(null, {
        statusCode: 200,
        body: JSON.stringify(response)
      })
    }).catch((error) => {
      console.log('error', error)
      return callback(null, …
Run Code Online (Sandbox Code Playgroud)

javascript faunadb

6
推荐指数
1
解决办法
539
查看次数

标签 统计

faunadb ×1

javascript ×1