为什么要显示这个?

时间:2013-11-10 01:51:43

标签: ember.js

我有以下模板:

  <script type="text/x-handlebars" data-template-name="projects">
    <div class="container-fluid">
      <div class="row-fluid">
        {{#linkTo "projects"}}Root{{/linkTo}}
        {{#each controller}}
          <div class="span4">
            {{#linkTo "projects.show" this}}{{this.name}}{{/linkTo}}
          </div>
        {{/each}}
      </div>
      {{outlet}}
    </div>
  </script>

  <script type="text/x-handlebars" data-template-name="projects/show">
    <h2>Overview of {{name}}</h2>
  </script>

以及app.js中的以下内容:

App = Ember.Application.create({
  LOG_TRANSITIONS: true
});

App.Project = DS.Model.extend({
  name: DS.attr("string"),
  key : DS.attr("string")
});

App.Router.map(function() {
  this.resource("projects",function() {
    this.route("show", {path: "/:project_id"});
  });
});

App.IndexRoute = Ember.Route.extend({
  redirect: function() {
    this.transitionTo("projects");
  }
});

App.ProjectsRoute = Ember.Route.extend({
  model: function() {
    return this.store.find("project");
  },
})

以及以下模型设置:

App.Store = DS.Store.extend({
  adapter: DS.FixtureAdapter // run with fixture data
});

App.Project.FIXTURES = [
  {
    id: 1,
    name: 'Proj1',
    key: "P1KEY"
  },
  {
    id: 2,
    name: 'Proj2',
    key: "P2KEY"
  },
];

当我第一次导航到该页面时,我看到以下3个链接(Root,Proj1和Proj2)。由于我最初是在索引视图中,所以我看到了:

enter image description here

然后,我点击第一个项目,我看到了:

enter image description here

最后我回到索引,但项目/节目的内容似乎仍然存在:

enter image description here

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

1 个答案:

答案 0 :(得分:1)

当你说回到索引时,你是说你点击Root链接?看起来它对我很有用:

http://emberjs.jsbin.com/IBECuSID/1/edit

顺便说一下,我上了一个更新版本的Ember Data,所以做了一个小改动:

App.ApplicationAdapter = DS.FixtureAdapter;