【问题标题】:Wordpress JSON API - remove characters from contentWordpress JSON API - 从内容中删除字符
【发布时间】:2014-09-25 11:29:18
【问题描述】:
我正在使用 Wordpress JSON API 插件将我的帖子获取为 json。我将这些数据用于我的 AngularJS 项目。如何从我通过 JSON api 获得的帖子内容部分中删除字符和 p 标签。
<p> Lorem ipsum text “times” </p>
所以我可以在我的页面上显示:
Lorem ipsum text "times"
【问题讨论】:
标签:
json
wordpress
api
character-encoding
json-api
【解决方案1】:
我遇到了同样的问题,但后来意识到我将内容附加为 textNode。在我将其设置为 innerHTML 后,它就起作用了。
所以,我的错误代码是:
var content = document.createElement('div');
content.setAttribute('class', 'story');
var contentText = document.createTextNode(post.content);
div.appendChild(contentText);
正确代码:
var content = document.createElement('div');
content.setAttribute('class', 'story');
content.innerHTML = post.content;
希望对某人有所帮助。