【问题标题】:Mustache template. Why is there no output小胡子模板。为什么没有输出
【发布时间】:2016-01-06 10:14:43
【问题描述】:

在屏幕上我可以输出Team:,但对应的teamName根本不输出。任何人都可以提出原因吗?

var $teams = $('#info');
var template = '<td> Team: {{standings.standing[0].teamName}} </td>';
$.ajax({
    headers: {
        'X-Auth-Token': '0fc841d392274cb5a26804330ac11e98'
    },
    type: 'GET',
    dataType: 'json',
    url: 'http://api.football-data.org/v1/soccerseasons/401/leagueTable',
    success: function(standings) {
        var output = Mustache.render(template, standings);
        $teams.append(output);
    }
});
<div class="container">
    <table class="u-max-full-width">
        <thead>
                <th>Serie A</th>
                <th>W</th>
                <th>D</th>
                <th>L</th>
                <th>Goals</th>
                <th>Diff</th>
                <th>Pt</th>
            </tr>
        </thead>
        <tbody>
            <tr id="info"></tr>
        </tbody>
    </table>
</div>

这是一个代码笔:http://codepen.io/bigheed/pen/OMpOza?editors=001

【问题讨论】:

标签: jquery templates mustache


【解决方案1】:

我改变了这两条线和它的作品,

var template = '{{#data}} <td> Team: {{teamName}} </td> {{/data}}';
var output = Mustache.to_html(template, {data:standings.standing});

【讨论】:

  • 这确实有效,尽管我不想遍历整个“数据”对象。
  • 如果您不想循环遍历数据对象,您可以尝试这样,{data:standings.standing[0]} 并更改模板 {{data.teamName}}
猜你喜欢
  • 1970-01-01
  • 2011-10-14
  • 1970-01-01
  • 2012-04-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多