重新加载路线emberjs

时间:2014-03-09 14:01:05

标签: javascript jquery ember.js

我有个人资料路线

 Remon.ProfileRoute=Ember.Route.extend({

    activate: function() {
    console.log("act");
  },

   model: function(params){
    return this.store.find("profile",params.profile_id);

 }
});

这是我的router.js

Remon.Router.map(function(){
 this.route("news");
  this.resource("profiles");
   this.resource("profile",{path:'profile/:profile_id'},function(){
 this.route("photos");
  });
 });

和我的链接帮助

  {{#link-to "profile" 1}}another profile {{/link-to}}

当我从个人资料主页访问个人资料时,它运行良好,激活方法也有效但当我在个人资料页面上并尝试访问另一个个人资料网址未更改但第二个个人资料的模型数据已加载 点击个人资料时,从个人资料主页

Attempting transition to profile.index ember.js?body=1:3462
Transition #33: profile: calling beforeModel hook ember.js?body=1:3462
 Transition #33: profile: profile: resolving provided model ember.js?body=1:3462
  Transition #33: profile: calling afterModel hook ember.js?body=1:3462
 Transition #33: profile.index: calling beforeModel hook ember.js?body=1:3462
 Transition #33: profile.index: calling deserialize hook ember.js?body=1:3462
 Transition #33: profile.index: calling afterModel hook ember.js?body=1:3462
 Transition #33: Resolved all models on destination route; finalizing transition. ember.js?body=1:3462
  act            profile_route.js?body=1:3
  Transitioned into 'profile.index' ember.js?body=1:3462
  Transition #33: TRANSITION COMPLETE

当我点击同一个个人资料页面上的另一个个人资料时,没有转换到新模型,但模板已更改为新数据,但网址保留了前一个

 Transition #34: profile: profile: resolving provided model ember.js?body=1:3462
Transition #34: profile: calling afterModel hook ember.js?body=1:3462
Transition #34: profile.index: calling beforeModel hook ember.js?body=1:3462
Transition #34: profile.index: calling deserialize hook ember.js?body=1:3462
 Transition #34: profile.index: calling afterModel hook ember.js?body=1:3462
  Transition #34: Resolved all models on destination route; finalizing 

在控制台中停在

   Resolved all models on destination route; finalizing transition.

和“过渡到'个人资料'没有出现,激活方法也没有被触发

更新

我想我发现错误在哪里 我有多个布局

 Remon.MainLayoutView = Ember.View.extend({


didInsertElement  : function(){
    console.log("pr");
    this._super();

  this.$('#simple-menu').sidr({
      name: 'sidr-left',
      side: 'left',
      source: '#myside',
      renaming: false
  });
},
willAnimateIn : function () {

    this.$().css("opacity", 0);
},

animateIn : function (done) {
    this.$().fadeTo(500, 1, done);
},

animateOut : function (done) {
    this.$().fadeTo(500, 0, done);
},
layoutName: 'layouts/application' });

Remon.ProfileView=Remon.MainLayoutView.extend();

删除animateout方法后,它现在可以使用了

1 个答案:

答案 0 :(得分:0)

根据activiate的文档:

  

当路由器进入路由时执行此挂钩。当路线模型改变时,不会执行。

似乎beforeModel可能是放置该代码的最佳位置,但我不确定您的意图是什么。你想做什么?

也就是说,当您在profile页面中更改模型时,您的网址应该会更改。你的link-to看起来像什么?

这是一个示例项目,它包含您的路由器并正确更改URL。

Full screen app(查看网址更改)

code on js bin

更新

我试图让您引用的库(Sidr)工作,但我无法(在合理的时间内)。我在控制台中收到Uncaught TypeError: Object [object Object] has no method 'sidr'

Here is the code

相关问题