首页 文章

当路由器具有动态段时,链接到序列化的emberjs-1.0问题

提问于
浏览
0

我有一个 jsfiddle with nested route ,我在另一条动态路线 appointment 中嵌套了一条动态路线 timeSlot . 在约会模板里面我有 #link-to 'timeSlot' . 单击该链接时, timeSlot template 永远不会呈现,在控制台中我看到:

This link-to is in an inactive loading state because at least one of its parameters presently has a null/undefined value, or the provided route name is invalid.

这是路由器 . 请注意,如果我将 timeSlot route 从动态路由更改为正常路由,即链接此事件 this.resource('timeSlot') ,则错误消失并显示模板 . 路线需要是动态的,因为它接受通过用户点击日历传递的日期 .

它是一个小jsfiddle, the jsfiddle 中95%的代码粘贴在这个问题中:

App.Router.map(function(){
  this.resource('appointments', {path: "/"}, function(){ 
    this.resource('appointment', {path: "/:appointment_id"}, function(){
       this.resource('timeSlot', {path: '/:day'});                       
    });     
  });   
});

预约路线

App.AppointmentRoute = Ember.Route.extend({
   model: function(params){ 
   },

   setupController: function(controller, model){
    this._super(controller, model);
    controller.set('content', model);
   }
 });

TimeSlot路线

App.TimeSlotRoute = Ember.Route.extend({
  model: function(params){   
  },

  setupController: function(controller, model) {
   this._super(controller, model);
   controller.set('content', model);       
  },

  serialize: function(dateText) {
    /*
   return { 
      day: //this.controllerFor('timeSlot').today.pushObject(dateText)};
       */
  } 
 });

约会模板

<script type="text/x-handlebars" data-template-name="appointment">
   
{{#link-to 'timeSlot' [2013-07-18]}}click timeSlot{{/link-to}} {{outlet}} </script>

时间槽模板

<script type="text/x-handlebars" data-template-name="timeSlot">
<h3> from timeslot template</h3>


{{outlet}}
</script>

update

对于此路由: this.resource('timeSlot', {path: ':appointment_id/:day'}); 通过 jsfiddle 中的 {{#link-to 'timeSlot' id=this day=['today'] }}click timeSlot{{/link-to}} 显式传递每个动态段的值到链接到,现在可以将鼠标悬停在链接上并查看 '#/2/dateText' ,其中每个斜杠段都是为了动态细分 . 在传递动态段的值之前,当我在链接上盘旋时,我看到的只是 /#' ,表明动态段未被选中 .

它仍然无法正常工作 . 因为它使用serialize方法中传递的硬编码值而不是传递给link-to的值 .

update 2

虽然#linkTo似乎没有调用序列化方法,但是这个版本正在运行 . http://jsfiddle.net/GQdbD/5/

1 回答

  • 1

    由于你所有的 model 挂钩都是空的,所以_1510046会重新尝试 . (它们在您的应用中实际上是空的吗?)通常,当您调用 link-totransitionTotransitionToRoute 时,Ember希望您传入实时模型 . 在这些情况下,将跳过路径上的 model 挂钩,而是使用传递给 link-to 的模型 .

相关问题