jquery/backbone/mustache/json将html呈现为文本字符串

Ale*_*lex 6 javascript wordpress jquery json backbone.js

太累了,我知道我以前见过这个,但谷歌并没有帮助我制作一个单页骨干驱动的WP主题.数据只是wordpress JSON API数据,我现在很乐意在一些项目中使用主干,但这次它的表现并不好......它正在这样做(显示html标签而不是......使用它们):

在此输入图像描述

这是渲染代码:

this.template = '<div class="post-list">{{#posts}}<article><h2>{{title}}</h2><span class="postcontent">{{content}}</span></article>{{/posts}}</div>';

            if(this.model.get("rawdata").posts!=undefined && this.model.get("rawdata").posts.length>0)
            {
                var posts = [];
                for(i=0;i<this.model.get("rawdata").posts.length;i++)
                {
                    posts[i] = new PostModel(this.model.get("rawdata").posts[i]);
                }
                this.postCollection = new PostCollection(posts);
                this.htm = Mustache.render(this.template,this.model.get("rawdata"));
                this.$el.empty().html(this.htm);
                log(this.htm)           
            }
            else
            {
                //handle no-data result error
            }
Run Code Online (Sandbox Code Playgroud)

mcc*_*002 10

尝试将变量名称放在模板中

{{& posts}}
Run Code Online (Sandbox Code Playgroud)

要么

{{& title}}
Run Code Online (Sandbox Code Playgroud)

一切都在文档中


abs*_*nce 8

另一种选择是使用三重胡须:

{{{title}}}
Run Code Online (Sandbox Code Playgroud)

它也在文档中.此选项也适用于Nustache.