I've been working to extend the grid system by adding custom settings to the grid editor but I'm having trouble accessing the data from the JSON feed. If a setting has not been applied to a single box in the grid layout nothing is added to the JSON data resulting in a null reference when trying to access the data. Is there a way to ignore null references or another way to accomplish this?
Here is the error message I receive.
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference
If I change the @area.config.backgroundColor to @area.config I can see the data in the front end but when I want to display the data for backgroundColor I get an error since not all boxes have a custom setting applied in the back office.
Here's an example of the data with a setting applied for backgroundColor
can you not wrap your request for the backgroundColor config setting in an if which first checks the truthy value of hasConfig just noting the difference in json in working and non working blocks. If there is no config and therefore an error is a bout to be thrown the value of hasConfig will be false otherwise true.
JSON null reference extending grid system
I've been working to extend the grid system by adding custom settings to the grid editor but I'm having trouble accessing the data from the JSON feed. If a setting has not been applied to a single box in the grid layout nothing is added to the JSON data resulting in a null reference when trying to access the data. Is there a way to ignore null references or another way to accomplish this?
Here is the error message I receive.
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference
If I change the @area.config.backgroundColor to @area.config I can see the data in the front end but when I want to display the data for backgroundColor I get an error since not all boxes have a custom setting applied in the back office.
Here's an example of the data with a setting applied for backgroundColor
And here is an example of a box that does not have a setting applied for backgroundColor. These boxes are causing the error.
can you not wrap your request for the backgroundColor config setting in an if which first checks the truthy value of hasConfig just noting the difference in json in working and non working blocks. If there is no config and therefore an error is a bout to be thrown the value of hasConfig will be false otherwise true.
That worked. Thanks.
is working on a reply...