Javascript 附加“;我";标记加上要跨越的文本

Javascript 附加“;我";标记加上要跨越的文本,javascript,angularjs,append,Javascript,Angularjs,Append,我用这个有角度的脚本来构建一个div。我遇到的问题是它在I标记中附加了.text,而不是作为I的兄弟 希望这是有意义的 var body = placeWrapper .append('div') .attr('class', 'thm-listing__body'); body.append('span') .attr('class', 't

我用这个有角度的脚本来构建一个div。我遇到的问题是它在I标记中附加了.text,而不是作为I的兄弟

希望这是有意义的

            var body = placeWrapper
                .append('div')
                .attr('class', 'thm-listing__body');

                body.append('span')
                .attr('class', 'thm-listing__location')
                .append('i')
                .attr('class', 'fa fa-map-marker')
                .text(function (d) {
                    return d.Address;
                });
假设此俯冲呈现如下所示:

<div class="thm-listing__body">
<span class="thm-listing__location">
<i class="fa fa-map-marker"></i>
The text here
</span>
</div>

这里的文字
但它目前呈现出:

<div class="thm-listing__body">
<span class="thm-listing__location">
<i class="fa fa-map-marker">The text here</i>
</span>
</div>

这里的文字

您正在将
text
设置为
i
标记,并且您希望span right有一个文本,因此将文本设置在append span之后,而不是append
i
之后,如下所示

    var body = placeWrapper
        .append('div')
        .attr('class', 'thm-listing__body');

        body.append('span')
        .attr('class', 'thm-listing__location')
        .text(function (d) {
            return d.Address;
        })
        .append('i')
        .attr('class', 'fa fa-map-marker');
更新

在使用span文本之前,请按照以下说明设置图标

var body = placeWrapper
            .append('div')
            .attr('class', 'thm-listing__body');

            body.append('span')
            .attr('class', 'thm-listing__location')
            .text(function (d) {
                return d.Address;
            })
            .prepend('i')
            .attr('class', 'fa fa-map-marker');

它需要在文本之前,我确实这样尝试过,但图标位于文本的末尾,而不是开头。请使用
prepend()
查找我的更新答案。对于此问题,它似乎不起作用:body.append(…).attr(…).text(…).prepend不是一个函数是我在上面使用prepend时遇到的错误你能做个提琴让我知道到底出了什么问题吗?这不是角度的方式。。。