我正在使用ember cli来生成我的项目结构。当我使用Mixin和Model扩展Route类时。模型停止在我的插座中显示。
controllers / application.js ::(ActiveclasscontrollerMixin仅用于提供应用程序级属性,用于确定哪个类属性处于活动状态 - 我提供此属性仅供参考,其他mixin ActiveclassrouteMixin.js在与路径的模型挂钩一起使用时导致问题。)
import Ember from 'ember';
import ActiveclasscontrollerMixin from 'embercliapp/mixins/activeclasscontroller';
export default Ember.Controller.extend(ActiveclasscontrollerMixin);
控制器/ posts.js
import Ember from 'ember';
var PostsController = Ember.ArrayController.extend();
export default PostsController;
template / posts.hbs (此模板在routes / posts.js时工作正常,仅在扩展Ember.Route对象时覆盖模型并显示所有2个帖子)
<div class="container-fluid">
<div class="row">
<div class="col-md-3">
<table class='table'>
<thead>
<tr><th>Recent Posts</th></tr>
</thead>
<tbody>
{{#each model}}
<tr>
<td>
{{#link-to 'post' this}}{{title}} <small class='muted'>by {{author.name}}</small>{{/link-to}}
</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
<div class="span9">
{{outlet}}
</div>
</div>
</div>
mixins / ActiveclasscontrollerMixin.js - (仅用于/controllers/application.js)
import Ember from 'ember';
export default Ember.Mixin.create({
isHome: '',
isPosts: '',
isAbout: '',
sayAlert: function(sayAlert){
alert(sayAlert);
},
setActiveClass: function(routeName) {
//alert('called setActiveClass:' + routeName);
if ((routeName === 'isHome') || (routeName === 'application') || (routeName === 'index')) {
this.set('isHome', 'active');
this.set('isPosts', '');
this.set('isAbout', '');
}
if (routeName === 'isPosts' || (routeName === 'posts')) {
this.set('isPosts', 'active');
this.set('isHome', '');
this.set('isAbout', '');
}
if (routeName === 'isAbout' || (routeName === 'about')) {
this.set('isAbout', 'active');
this.set('isPosts', '');
this.set('isHome', '');
}
},
actions: {
clickedAction: function(routeName) {
this.setActiveClass(routeName);
}
}
});
混入/ ActiveclassrouteMixin.js
import Ember from 'ember';
export default Ember.Mixin.create({
setupController: function(controller) {
this._super(controller);
var routeName = this.get('routeName');
this.controllerFor('application').setActiveClass(routeName);
}
});
路由/ posts.js
import Ember from 'ember';
import ActiveclassrouteMixin from 'embercliapp/mixins/activeclassroute';
var posts = [{
id: '1',
title: "Rails is Omakase",
author: {
name: "d2h"
},
date: new Date('12-27-2012'),
excerpt: "There are lots of à la carte software environments in this world. Places where in order to eat, you must first carefully look over the menu of options to order exactly what you want.",
body: "I want this for my ORM, I want that for my template language, and let's finish it off with this routing library. Of course, you're going to have to know what you want, and you'll rarely have your horizon expanded if you always order the same thing, but there it is. It's a very popular way of consuming software.\n\nRails is not that. Rails is omakase."
}, {
id: '2',
title: "The Parley Letter",
author: {
name: "d2h"
},
date: new Date('12-24-2012'),
excerpt: "My [appearance on the Ruby Rogues podcast](http://rubyrogues.com/056-rr-david-heinemeier-hansson/) recently came up for discussion again on the private Parley mailing list.",
body: "A long list of topics were raised and I took a time to ramble at large about all of them at once. Apologies for not taking the time to be more succinct, but at least each topic has a header so you can skip stuff you don't care about.\n\n### Maintainability\n\nIt's simply not true to say that I don't care about maintainability. I still work on the oldest Rails app in the world."
}];
export default Ember.Route.extend({
model: function() {
return posts;
}
});
在上面这种情况下,一切都按预期工作。但是,如果我在扩展路线时添加使用mixin(ActiveclassrouteMixin)以及模型,模型将停止在插座中显示:
export default Ember.Route.extend(ActiveclassrouteMixin,{
model: function() {
return posts;
}
});
并且commond cli构建/服务进程或chrome javascript控制台中没有错误。
答案 0 :(得分:2)
我会将所需的代码提炼为:
fopen()
f_in = fopen(argv[1], "rb");
if ( NULL == f_in )
{
// handle error
.
.
.
controller.js
setupController: function(controller, models) {
this._super(controller, models); // insure mixin.setupController() called
controller.setProperties( models );
}
现在,您可以在mixin中设置模型的属性!
答案 1 :(得分:0)
想出来,所以Mix-in:ActiveclassrouteMixin有一个方法setupController:function(controller),显然缺少模型。将其更改为
setupController: function(controller,model) {
this._super(controller,model);
var routeName = this.get('routeName');
this.controllerFor('application').setActiveClass(routeName);
}