using a string variable in request results in the the variable name being used instead of its content
kartur opened this issue · comments
I'm new to JS way of life, so please forgive me if this is some mistake on my side
Describe the bug
Here is a simple example. Let's assume we want to change the name of an employee. (It's basically very similar to the examples in the guide, except I need to use a string variable (attributeName) for the resource name)
attributeName = 'name'
traverson
.from(emp._links.self.href)
.json()
.put({ attributeName : emp[attributeName]}, function(error, document) {
if (error) {
console.error(error)
} else {
console.log('UPDATED Employee (' + attributeName + ') to ' + emp[attributeName])
}
})
But this doesn't work, because instead of 'name' being used, the request is literally using the variable name 'attributeName'
Expected behavior
I think it should use the variable content instead of the variable name.
Browser/Desktop (please complete the following information):
- OS: Windows 10
- Browser: Chrome
- Browser version: 77.0.3865.90
- Traverson Version: 7.0.0-alpha.5 (2019-06-15)
Nevermind, this is a javascript thing and has nothing to do with traverson.
If anyone is wondering, you can just put the variable name in square brackets (Computed Property Names):
.put({ [attributeName] : emp[attributeName]}, function(error, document) {