However, when I view this in the back office, it is coming up with:
[object Object]
Before I have tried taking out the outer [] before storing the JSON data and then adding it back in when I need to use it however, that only works if there are multiple objects in my JSON. In this case stripping those outer brackets produces the following:
I have tried this where the field is a multi line text field as well as in my own custom property which again is just a text field but read only. In both cases the JSON is not shown to the user in the back in. How do I ensure the JSON appears to my users in the back end without corrupting the JSON that is stored?
Does Umbraco give you any errors - eg. in the developer console? Are you sure the property has a value? I think the default value is just an empty string, so that wouldn't show up in the editor.
If you add the controller again, you can do something like the code below to write the value to the developer console:
angular.module("umbraco")
.controller("Axum.ReadOnly",
function ($scope) {
console.log($scope.model.value);
});
Yes the property has a value. No Umbraco does not give any errors. The value is what I pasted above as I have checked in the database and through debugging what my code enters programm
I just want this to be presented to the screen but I think that because it is JSON it is not possible for Angular to display it as it always interprets it as an object.
As a workaround, you could create a property editor that prefixes the text (or, say, base64 encodes it) before storing it to the server. That way, you could avoid having Umbraco detect it as JSON (which is the root of the problem). You really only need to prefix a value, as Umbraco is just looking at the beginning and end of the string to determine if it's JSON.
I think there is a way to convert that data back to the clean JSON version on the server so the code making use of it is completely unaware that it's a specially encoded string.
A property value converter might work, but I think there's another concept in Umbraco that manages converting objects before/after storing it to/retrieving it from the database. Can't remember off the top of my head what that is.
Storing JSON data in Umbraco
Hi all,
I am trying to store the following JSON string in Umbraco:
However, when I view this in the back office, it is coming up with:
Before I have tried taking out the outer [] before storing the JSON data and then adding it back in when I need to use it however, that only works if there are multiple objects in my JSON. In this case stripping those outer brackets produces the following:
This again displays as:
I have tried this where the field is a multi line text field as well as in my own custom property which again is just a text field but read only. In both cases the JSON is not shown to the user in the back in. How do I ensure the JSON appears to my users in the back end without corrupting the JSON that is stored?
Any help would be greatly appreciated.
Hi Jason,
Do you have an example of your view? Is this a property editor, and if so, what should it do?
Anyways, if you just write something like
{{model.value}}
, Angular/JavaScript will just call the toString() method of the object.If you want to visualize the value, you can write something
{{model.value | json}}
. This tells AngularJS to serialize the object into a JSON string.Not sure whether this answers your question, but if you can post your view (and perhaps controller), I can have another look at it ;)
Hi Anders,
Here is my controller and editor code below. Nothing special it just outputs a read only field.
Controller
View
Given that your controller doesn't do anything, you don't actually need it.
Since your textarea is readonly (I'm assuming you edit the value somehow programatically), you can just do something like:
When I do what you have suggested, nothing is displayed.
Does Umbraco give you any errors - eg. in the developer console? Are you sure the property has a value? I think the default value is just an empty string, so that wouldn't show up in the editor.
If you add the controller again, you can do something like the code below to write the value to the developer console:
Yes the property has a value. No Umbraco does not give any errors. The value is what I pasted above as I have checked in the database and through debugging what my code enters programm
I just want this to be presented to the screen but I think that because it is JSON it is not possible for Angular to display it as it always interprets it as an object.
Hey pals,
at the moment i have exactly the same problem but need to display the json content at the UI of Umbraco.
As Document Type we use a simple multiple textbox multiple.
Any updates on this topics? Some hints?
I've encountered this Umbraco bug and reported it here: http://issues.umbraco.org/issue/U4-7382
Feel free to vote on it there.
As a workaround, you could create a property editor that prefixes the text (or, say, base64 encodes it) before storing it to the server. That way, you could avoid having Umbraco detect it as JSON (which is the root of the problem). You really only need to prefix a value, as Umbraco is just looking at the beginning and end of the string to determine if it's JSON.
I think there is a way to convert that data back to the clean JSON version on the server so the code making use of it is completely unaware that it's a specially encoded string.
A property value converter might work, but I think there's another concept in Umbraco that manages converting objects before/after storing it to/retrieving it from the database. Can't remember off the top of my head what that is.
Ideally, the core team would just fix the bug.
Hi all,
I would like to have editable textarea with JSON data.
How my model can save to DB with this html?
Thanks, Mike
is working on a reply...