node-projects / web-component-designer

A Designer for HTML Components or Pages in a WebComponent
https://node-projects.github.io/web-component-designer-demo/index.html
MIT License
148 stars 16 forks source link

Json object cannot be parsed into html attribute #340

Closed MatariAbdulwahid closed 1 year ago

MatariAbdulwahid commented 1 year ago

hi, when we wanted to set a JSON object as Html attributes then it does not parse correctly. I debugged and found that the problem lies in this place and there item.attributes does not come the attribute just like the others.

let attr = item.attributes; https://github.com/node-projects/web-component-designer/blob/9f13474d32990bfccff9ce1d5e556086be457e8b/src/elements/services/htmlParserService/NodeHtmlParserService.ts#L59

Example:

<div instansFilter="{"id" : "name" :"abdul"}"></div> at Debug also looks like this

image

what you see the error the package node-html-parser

jogibear9988 commented 1 year ago

Try single quotes for the attribute, as json contains double quotes.

MatariAbdulwahid commented 1 year ago

with single quotes it works, but when I set the attributes, then the default is "double quotes", the attributes are set with double quotes and here is the problem

jogibear9988 commented 1 year ago

I‘ll check

jogibear9988 commented 1 year ago

Where is it the default? If I set a json object via attributes property editor, it works and the attribte starts with a single dash. You could also use double quotes, but then you have to encode the json double quotes with &quot;

jogibear9988 commented 1 year ago

Tell me exactly what you do, but I don't think there is an error.

jogibear9988 commented 1 year ago

Also the Json would be parsed in the "htmlWriterService"and beatyified, this is the default behavior.

jogibear9988 commented 1 year ago

@MatariAbdulwahid any more questions?

MatariAbdulwahid commented 1 year ago

I have checked the "htmlWriterService" and there is no error, json attributes are written with single quataions and the error was in my code when I set the content (outerHTML) in DocumentContainer-content then the single qutations are converted to double. So there is no error and I thank you for the tips