Ember.js 告诉余烬重新加载组件
我定义了一个组件,如下所示:Ember.js 告诉余烬重新加载组件,ember.js,discourse,Ember.js,Discourse,我定义了一个组件,如下所示: export default Ember.Component.extend({ classNameBindings: ['isCategory'], didInsertElement: function() { Ember.addObserver(Discourse, 'currentPath', this.routeChanged); }, routeChanged: function(){ var route = Discou
export default Ember.Component.extend({
classNameBindings: ['isCategory'],
didInsertElement: function() {
Ember.addObserver(Discourse, 'currentPath', this.routeChanged);
},
routeChanged: function(){
var route = Discourse.get('currentPath');
if (route == 'discovery.top') {
this.set('path', '/top');
this.set('label', 'top');
} else if (route == 'discovery.categories'){
this.set('path', '/categories');
this.set('label', 'Categories');
} else {
this.set('path', '/latest');
this.set('label', 'Latest');
}
},
render: function(buffer) {
this.routeChanged();
buffer.push('<a href="' + this.get('path') + '">' + this.get('label') + '</a>');
}
});
由该组件支持:
export default Ember.Component.extend({
classNameBindings: ['isCategory'],
templateName: "components/memory-nav",
didInsertElement: function() {
Ember.addObserver(Discourse, 'currentPath', this.routeChanged);
}.on('init'),
routeChanged: function(){
var route = Discourse.get('currentPath');
if (route == 'discovery.top') {
Ember.Logger.log("Top");
this.set('path', '/top');
this.set('label', 'Top');
} else if (route == 'discovery.categories'){
Ember.Logger.log("Cateogries");
this.set('path', '/categories');
this.set('label', 'Categories');
} else {
Ember.Logger.log("Latest");
this.set('path', '/latest');
this.set('label', 'Latest');
}
}.on('init')
});
这现在可以工作了,并且在路径更改时正确调用日志。我原以为在对象上调用
.set
会自动更新模板,但目前还没有更新。我缺少什么?为什么需要重新渲染整个组件,而不仅仅是更改的部分?这就是Ember双向绑定的全部要点。我和David有同样的问题。当你说只渲染重要的部分时,你指的是子组件?不管怎样,他会怎么做?如果我被迫观察并调用re render,请不要在这里真正获得双向数据绑定
export default Ember.Component.extend({
classNameBindings: ['isCategory'],
templateName: "components/memory-nav",
didInsertElement: function() {
Ember.addObserver(Discourse, 'currentPath', this.routeChanged);
}.on('init'),
routeChanged: function(){
var route = Discourse.get('currentPath');
if (route == 'discovery.top') {
Ember.Logger.log("Top");
this.set('path', '/top');
this.set('label', 'Top');
} else if (route == 'discovery.categories'){
Ember.Logger.log("Cateogries");
this.set('path', '/categories');
this.set('label', 'Categories');
} else {
Ember.Logger.log("Latest");
this.set('path', '/latest');
this.set('label', 'Latest');
}
}.on('init')
});