This is a migrated thread and some comments may be shown as answers.

Trouble with observableObject getter + setter and special object attributes

1 Answer 192 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Bridge24
Top achievements
Rank 1
Iron
Bridge24 asked on 30 May 2019, 07:44 PM
Hi, we are using the "btoa" method to generate field name in some of our objects.

We have no problems with these attributes until we make them "observable".
The "btoa" algorithm can return some special characters, "+", "=" and "/".

Even if it looks strange, that is valid javascript / JSON property names.
Javascript can handle this.  

And observable too, until we use getters / setters.

Take a look at this dojo with a sample that explains everything.

var obj = new kendo.data.observableObject({});
var field = "field/";
obj[field] = "test"; // works
obj.set(field, "test"); // crash
value = obj[field]; // works
value = obj.get(field); // crash

Thank you

1 Answer, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 03 Jun 2019, 12:55 PM
Hello Daniel,

Internally we create function getters and setters for the properties of the observable object using the Function constructor. Within the body of those functions we use the field names as variables, therefore the names of the fields should be valid JS variable names. 

As +, =, - are actually operators in JS, you are not allowed to use them in the names of variables.

I hope this helps.


Regards,
Georgi
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Data Source
Asked by
Bridge24
Top achievements
Rank 1
Iron
Answers by
Georgi
Telerik team
Share this question
or