use*_*445 2 javascript ember.js
我的应用程序有两个控制器,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 {{controllers.login.code}}
{{ loadModel }} <!-- call loadModel function to populate model when this is rendered -->
{{#each model}}
<p>givenName {{givenname}}</p>
{{/each}}
{{else}}
<i>Please login first!</i>
{{/if}}
</script>
Run Code Online (Sandbox Code Playgroud)
你几乎就在那里,在你的模板中,你正在做的事情,弃用警告来自controllerFor你可以避免让你的登录控制器这样的调用this.get('controllers.login'),这里你的代码修改:
App.RsvpController = Ember.ArrayController.extend({
needs: ['login'], // borrows from login controller
content: [],
loadModel : function() {
var theCode = this.get('controllers.login.code'); // here the change
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)
希望能帮助到你
| 归档时间: |
|
| 查看次数: |
1398 次 |
| 最近记录: |