0

试图按照这个例子(现在已经将 ember 更新到 1.0rc2),我想嵌套模板来开始。{{outlet}}我在模板中有第一个附加项home,我希望它包含两个嵌套视图(一个“简历”span9和另一个“工具表” span3,供引导爱好者使用)。“简历”将再次具有嵌套模板,但一旦我能通过第一级,我想我可以。

根据这个SO?,以及我编辑的JS Fiddle 答案,我有点看到它是如何完成的,但是,答案在咖啡脚本中,并且示例中的路由器比我能理解的要复杂一些(使用connectOutlets,给定它的一些助手方法,我自己有点理解。

最终结果应该看起来像这样 fiddle

但是我如何让其他模板在家庭路由器中呈现,因为sections路由器和items路由器位于不同的路径上,但是,这些将是索引路由的一部分/?我是否需要多个{{outlets}}?,以及如何将适当的模板路由到适当的插座占位符?

信息:

DEBUG: ------------------------------- 
DEBUG: Ember.VERSION : 1.0.0-rc.2 
DEBUG: Handlebars.VERSION : 1.0.0-rc.3 
DEBUG: jQuery.VERSION : 1.9.1 
DEBUG: ------------------------------- 

索引.html:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Resume Builder</title>
    <meta name="description" content="A way to create a tailored resume from my CV" />
    <meta name="author" content="Chris Frisina" />

    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

    <link href="css/bootstrap.min.css" rel="stylesheet" />
    <style>
      body {
        padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
      }
    </style>
    <link href="css/bootstrap-responsive.css" rel="stylesheet" />
    <link href="css/RB.css" rel="stylesheet" />
  </head>

  <body>

    <script src="js/libs/jquery-1.7.1.js"></script>
    <script src="js/libs/jquery.lorem.js"></script>
    <script src="js/libs/bootstrap.min.js"></script>
    <script src="js/libs/handlebars-1.0.0.beta.6.js"></script>
    <!-- // <script src="js/libs/ember1.js"></script> -->
    <script src="js/libs/ember2.js"></script>
    <script src="js/RB.js"></script>

    <script type="text/x-handlebars" data-template-name="application">
      <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="navbar-inner">
          <div class="container-fluid">
            <div class="brand home" {{bindAttr class="isHome:active"}} {{action "doHome"}}>Chris Frisina</div>
            <div class="nav-collapse pull-right">
              <ul class="nav">
                <li class="sections"><a>1</a></li>
                <li class="sections"><a>2</a></li>
              </ul>
            </div>
          </div>
        </div>
      </div>

      <div class="container-fluid">
        {{outlet}}
      </div>
    </script>

    <script type="text/x-handlebars" data-template-name="index">
      <h3 class="demo-panel-title">This is the index template</h3>
      {{home}}
    </script>

    <script type="text/x-handlebars" data-template-name="home">
      <div class="row-fluid">
        <!-- This is where I resume template should be placed -->
        {{resume}}
        <!-- This is where I tooltable template should be placed -->
        {{tooltable}}
      </div>
    </script>

    <script type="text/x-handlebars" data-template-name="resume">
      <div class="span9">
        <h1>Viewer</h1>
      </div>
    </script>

    <script type="text/x-handlebars" data-template-name="tooltable">
      <div class="span3">
        <div id="tooltable" class="tooltable hero-unit affix">
          <h1>Tooltable</h1>
          <p>Selector 1</p>
          <p>Selector 1</p>
        </div>
      </div>
    </script>

  </body>
</html>

应用程序.js:

// Attach the application to window
window.RB = Ember.Application.create({});

// Define the main application controller. This is automatically picked up by
// the application and initialized.
RB.ApplicationController = Ember.Controller.extend({

});
RB.ApplicationView = Ember.View.extend({
  templateName: 'application'
});

// Router
RB.Router = Ember.Router.extend({

});
RB.Router.map(function(){

});

// Home
RB.HomeController = Ember.Controller.extend({
});
RB.HomeView = Ember.View.extend({
  templateName: 'home',
});
// Resume
RB.ResumeController = Ember.ObjectController.extend({
});
RB.ResumeView = Ember.View.extend({
  templateName: 'resume'
});

// Tooltable
RB.TooltableController = Ember.ObjectController.extend({
});
RB.TooltableView = Ember.View.extend({
  templateName: 'tooltable'
});

//Defer the start until advanceReadiness() is complete
// cant init RB manually, must use advanceReadiness(), which needs defer...
RB.deferReadiness();
// var test = function() {
  RB.advanceReadiness();
// });
4

1 回答 1

3

我无法回答整个问题,但我可以先举例说明如何嵌套模板并编写使用它们的路线

App.Router.map(function(match) {
    this.resource("days", { path: "/days" }, function() {
        this.resource("day", { path: "/:day_id" }, function() {
            this.resource("appointments", { path: "/appointments" }, function() {
                this.resource("appointment", { path: "/:appointment_id" }, function() {
                    this.route("edit", { path: "/edit" });
                });
            });
        });
    });
});

对于上面的示例路线,我计划让用户从 /days 到特定日期 /days/1 点击

然后在那一天内,我希望他们能够显示所有约会

然后在约会中,我想让他们能够“点击”特定的apt并显示或编辑它

因为我的应用程序以天数路线开始,所以在我的应用程序索引中,我想在应用程序启动时立即跳转到天数(例如,我的应用程序从 /days 开始而不是从 /days 开始)

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

模板看起来像这样

application.handlebars (或者如果你内联它)

{{outlet}}

days.handlebars

{{#each day in controller}}
  {{#linkTo 'day' day}}view details about the day{{/linkTo}}
{{/each}}

{{outlet}}

day.handlebars

{{#linkTo "appointments" target="controller"}}show all the apts{{/linkTo}}

约会.车把

{{#each appointment in controller}}
<a href="#" {{action 'addAppointment' appointment target="view"}}>{{appointment.start}} - {{appointment.end}}</a><br />
{{/each}}

我的约会路线如下所示(提供上述模板中的约会)

App.AppointmentsIndexRoute = Ember.Route.extend({
    model: function(params) {
        var day = this.modelFor("day");
        return day.get('appointments');
    }
});
于 2013-04-02T15:34:29.783 回答