2014-10-06 60 views
0

我是新的emberJS。我试图让自己的头脑明白, Route-Template-Controller-View-Model。更改模型/控制器中的特定模板emberJS

这里是我的代码:// app.js

App.IndexRoute = Ember.Route.extend({ 
model: function() { 
    return App.FIXTURES; // some data for the index route 
}, 
setupController: function(controller, model) { 
    var self = this; 
    // sets the model for the current route 
    controller.set('model', model); 

    // render the dashboard template, 
    // Problem: I want the model of this template 'dashboard' to be changed, 
    // how can I achieved that? 
    self.render('dashboard', { 
     // Is this correct here? I pass an anonymous function to change the controller? 
     // I got an error for doing so 
     controller: function() { 
      console.log(this); 
     } 
    }); 
    } 

});

回答

0

你不应该需要调用渲染,烬处理所有为你。如果你有一个名为“index”的模板,它会自动渲染它,或者你可以在你的IndexView上设置模板。

如果你想改变模型,而不是controller.set('model', model);不使用通过模型,利用this.storehttp://emberjs.com/guides/models/finding-records/ 找到一个,并设置控制器上的模型。

+0

嗨,'self.render('仪表板')'有另一个模板要呈现。因为我想让模板的模型设置为另一个模型,可能吗?或者我的做法是错误的? – meetmahpuppy 2014-10-06 07:54:07

+0

@meetmahpuppy如果您想要在视图模板中加载模板,您可以使用'{{render}}帮助程序将其加载到指定的模型中http://emberjs.com/guides/templates/rendering-with-helpers / – Jakeii 2014-10-06 09:39:18