【发布时间】:2016-02-04 02:49:42
【问题描述】:
我正在使用一个有趣的 API,该 API 在它自己的对象中返回资源的每个元素。我将来自 ng-repeat 的数据传递到一个指令中,然后我需要返回完整的 HTML 字符串。对 lodash 来说是全新的,并且在弄清楚这一点时遇到了一些麻烦。段类型有很多可能性,我最终需要有案例。 View API Docs
- 链接
- 提及
- 标签
- 标记开始
- 标记结束
- 等
NG 指令
angular.module('Community.directives.feedBody', [])
.directive('feedBody', function feedBodyDirective() {
return {
restrict: 'E',
link: convertSegments
};
function convertSegments($scope, elem, attrs) {
var content = attrs.content;
}
}
);
JSON
[
{
"htmlTag": "p",
"markupType": "Paragraph",
"text": "",
"type": "MarkupBegin"
},
{
"text": "This is a ",
"type": "Text"
},
{
"htmlTag": "b",
"markupType": "Bold",
"text": "",
"type": "MarkupBegin"
},
{
"text": "post",
"type": "Text"
},
{
"htmlTag": "b",
"markupType": "Bold",
"text": "",
"type": "MarkupEnd"
},
{
"text": " from the standard ",
"type": "Text"
},
{
"htmlTag": "i",
"markupType": "Italic",
"text": "",
"type": "MarkupBegin"
},
{
"text": "chatter",
"type": "Text"
},
{
"htmlTag": "i",
"markupType": "Italic",
"text": "",
"type": "MarkupEnd"
},
{
"text": " UI with some HTML tags",
"type": "Text"
},
{
"htmlTag": "p",
"markupType": "Paragraph",
"text": "\n",
"type": "MarkupEnd"
}
]
UI 路由模板
<feed-body content="{{comment.body.messageSegments}}"></feed-body>
应该返回
<p><b>post</b> from the standard <i>chatter</i> ui with some HTML tags</p>
【问题讨论】:
标签: javascript angularjs loops lodash