grapesjs - Adding attributes to data object gets overridden - Stack Overflow

SummaryonStore method runs for the first timedata.test = 'test'the data object is saved

Summary

onStore method runs for the first time

data.test = 'test' // the data object is saved and stored to database
console.log(data.test) // 'test'

onStore runs for the second time

console.log(data.test) // is undefined

I am expecting data.test to be equal to "test"

Code

In the onSave method below, I add an attribute to the data object like:

data.test = 'test'

The next time onSave runs we check if the thing we added is there

console.log(data.test) //  returns undefined

How can I add values to the data object?

Full code

  storageManager: {
      type: 'remote',
      stepsBeforeSave: 1,
      autosave: true, 
      autoload: true, 
      options: {
        remote: {
          urlLoad: API_URL_GET,
          urlStore: API_URL_INSERT,

          onStore: (data) => {
            data.test = 'test'
            console.log(data.test) // always returns undefined
            console.log('Storing data:', data)
            return { id: PROJECT_ID, data }
          },
          onLoad: (result) => {
            console.log('Loading data:', result)
            const lastItem = result[Object.keys(result).length - 1]
            return lastItem ? JSON.parse(lastItem.data).data : {}
          },
        },
      },
    },

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744717341a4589698.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信