我的应用程序有两个控制器,LoginController和RsvpController.我想加载与当前登录相关的Rsvps列表.
我的登录代码似乎有效 - 但是我无法避免以下警告:"DEPRECATION:Controller#controllerFor已被弃用,请使用Controller#needs"
我也怀疑我不是在做烬的方式,所以我很感激如何改进这些代码以使用更多的ember功能.
这是控制器:
App.RsvpController = Ember.ArrayController.extend({
needs: ['login'], // borrows from login controller
content: [],
loadModel : function() {
var theCode = this.controllerFor('login').get('code');
console.log("Loading Model for code " + theCode);
var rsvpArray = App.Rsvp.find({
code : theCode
});
this.set('content', rsvpArray);
rsvpArray.addObserver('isLoaded', function() {
console.log("Loaded rsvpArray" + Em.inspect(this));
});
}.property('controllers.login.code'), // reload model if the user changes login
});
Run Code Online (Sandbox Code Playgroud)
这是index.html的一部分:
<script type="text/x-handlebars" id="rsvp">
<p>placeholder for <b>RSVP</b></p>
{{#if controllers.login.name }}
<!-- rsvp code here -->
Logged in with code …Run Code Online (Sandbox Code Playgroud)