Ember模板不显示

时间:2014-07-22 04:42:15

标签: django ember.js handlebars.js

我正在关注this指南,为ember.js和django设置令牌身份验证,但没有呈现任何车把模板。我已经删除了大部分代码,以找到最小的失败示例:

在" index.html"

{% load staticfiles %}

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>MySite</title>
    <link href="{% static 'bower_components/bootstrap/dist/css/bootstrap.min.css' %}" rel="stylesheet">
  </head>
  <body>
    {% verbatim %}
      <script type="text/x-handlebars">
        <h2>Hello world</h2>
        {{outlet}}
      </script>
    {% endverbatim %}
    <script src="{% static 'bower_components/jquery/dist/jquery.min.js' %}"></script>
    <script src="{% static 'bower_components/bootstrap/dist/js/bootstrap.min.js' %}"></script>

    <script src="{% static 'bower_components/handlebars/handlebars.js' %}"></script>
    <script src="{% static 'bower_components/ember/ember.js' %}"></script>
    <script src="{% static 'bower_components/ember-data/ember-data.js' %}"></script>
    <script src="{% static 'bower_components/ember-data-django-rest-adapter/build/ember-data-django-rest-adapter.js' %}"></script>
    <script src="{% static 'application.js' %}"></script>
  </body>
</html>

在&#34; application.js&#34;

window.App = Ember.Application.create();
App.ApplicationAdapter = DS.DjangoRESTAdapter.extend({});
App.ApplicationSerializer = DS.DjangoRESTSerializer.extend({});

App.ApplicationController = Ember.Controller.extend({
    needs: 'auth'
});

App.AuthController = Ember.ObjectController.extend({
    token: null,

    hasValidToken: function() {
        return false;
    }.property('token')
});

App.ApplicationRoute = Ember.Route.extend({
    init: function() {
        this._super();
        console.log('ok...');
        console.log(this.controllerFor('auth').hasValidToken());
    }
});

问题似乎出现在hasValidToken中,因为控制台记录了&#34; ok ...&#34;但之后什么都没有。

有人可以解释发生了什么吗?

1 个答案:

答案 0 :(得分:2)

hasValidToken是一个计算属性,因此您需要在其上使用getter。

console.log(this.controllerFor('auth').get('hasValidToken'));