无法在骨干模板中显示数据

时间:2013-10-17 15:03:59

标签: templates backbone.js

我有一个数据:

{
   "error":false,
   "data":{
      "category":"default",
      "resultCount":3,
      "results":[
         {
            "id":"",
            "articleId":"_9773721056",
            "sourceCount":0,
            "groupId":1,
            "newsText":"Solution Partner Onboarding and Support Specialist",
            "source":"Tech Vibes",
            "dateText":"Sep 10, 20:00 PDT",
            "sourceAccessStatus":0,
            "docType":"",
            "commonArticles":[
            ]
         },
         {
            "id":"",
            "articleId":"_9732124200",
            "sourceCount":0,
            "groupId":0,
            "newsText":"HootSuite Partners with Nexgate to Improve Social Security",
            "source":"Big News Network",
            "dateText":"Sep 05, 12:07 PDT",
            "sourceAccessStatus":0,
            "docType":"",
            "commonArticles":[
            ]
         },
         {
            "id":"",
            "articleId":"_9685221995",
            "sourceCount":0,
            "groupId":2,
            "newsText":"SugarCRM Teams up with HootSuite",
            "source":"Destination CRM",
            "dateText":"Aug 30, 14:04 PDT",
            "sourceAccessStatus":0,
            "docType":"",
            "commonArticles":[
            ]
         }
      ],
      "agentId":29,
      "agentName":"Partnerships",
      "mode":"SellingTrigger"
   },
   "errorMessage":""
}

我写的模板如下:

<div class="article-title">
    <a class="article article_tooltip" target="_blank"><%=newsText%></a>
</div>

但在html中,结果只显示:<%=newsText%>,而不是真实数据,我不知道为什么。希望得到你的帮助。谢谢。

1 个答案:

答案 0 :(得分:0)

好像你忘记编译模板了:

Backbone.View.extend({
  template: _.template('.. <%= newsText %> ..'),
  render: function () {
    this.$el.html(this.template(yourErrorJSON));
    return this;
  }
});