[英]Ruby on rails 3 - Using checkbox field inside form_for , sending html and json both request in ajax call , it should be js or json
[英]rails unable to store html inside json field
我嘗試創建 json 並將其存儲在 json 字段中,但所有 html 標記都更改為某些代碼
@vs=@tvrs.vsrs.new()
@vs.jsr = ({"desc": "<html>\n<body>\n<ul>\n <li>Generate client.</li>\n <li>In every month.
</li>\n \n</ul> \n\n\n\n</body>\n</html>"})
@vs.save()
存儲后顯示:-
{"id":11,"jsr":{"desc":"\u003chtml\u003e\n\u003cbody\u003e\n\u003cul\u003e\n \u003cli\u003eGenerate client.\u003c/li\u003e\n \u003cli\u003eIn every month.\u003c/li\u003e\n \n\u003c/ul\u003e \n\n\n\n\u003c/body\u003e\n\u003c/html\u003e"},"tvr_id":1,"created_at":"2020-06-12T04:01:16.116Z","updated_at":"2020-06-12T04:01:16.116Z"}
預期輸出:-
{"id":11,"jsr":{"desc": "<html>\n<body>\n<ul>\n <li>Generate client.</li>\n <li>In every month.
</li>\n \n</ul> \n\n\n\n</body>\n</html>"},"tvr_id":1,"created_at":"2020-06-12T04:01:16.116Z","updated_at":"2020-06-12T04:01:16.116Z"}
你有沒有嘗試過:
# let's assume you have a @vs instance variable which has an attribute jsr.
JSON.parse(@vs.jsr)
=> {"desc": "<html>\n<body>\n<ul>\n <li>Generate client.</li>\n <li>In every month. </li>\n \n</ul> \n\n\n\n</body>\n</html>"}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.