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条)