我正在尝试了解Ember View事件。
在视图中捕获内容更改的是什么事件?起初,我认为是didInsertElement,但在我的测试(下图)中,当PeopleView和(虚拟)CatView之间发生更改时,我无法捕获事件。 有人可以帮帮我吗?
JSFiddle:http://jsfiddle.net/3duardo/EM6FT/1/
的index.html:
<script type="text/x-handlebars" data-template-name="say-hello">
Hello, <b>{{view.name}}</b>
</script>
<script type="text/x-handlebars" data-template-name="peoples">
<p>Hi, peoples!</p>
</script>
<script type="text/x-handlebars" data-template-name="cats">
<p>Hi, cats!</p>
</script>
<script type="text/x-handlebars" data-template-name="application">
Oi {{view App.GregView}}
{{#link-to 'peoples'}}Pessoas{{/link-to}}
{{#link-to 'cats'}}Gatos{{/link-to}}
{{outlet}}
</script>
app.js
App = Ember.Application.create();
App.Router.map(function(){
this.resource('peoples');
this.resource('cats');
});
var view = Ember.View.create({
templateName: 'say-hello',
name: "Bob"
});
App.GregView = Ember.View.create({
templateName: 'say-hello',
name: "Greg",
didInsertElement: function () {
console.log('Ga')
},
parentViewDidChange: function () {
console.log('Gb')
},
willClearRender: function () {
console.log('Gc')
},
willInsertElement: function () {
console.log('Gd')
}
});
App.IndexView = Ember.View.extend({
didInsertElement: function () {
console.log('a')
},
parentViewDidChange: function () {
console.log('b')
},
willClearRender: function () {
console.log('c')
},
willInsertElement: function () {
console.log('d')
}
});
App.PeopleRoute = Ember.Route.extend({});
App.PeopleView = Ember.View.extend({
didInsertElement: function () {
console.log('Pa')
},
parentViewDidChange: function () {
console.log('Pb')
},
willClearRender: function () {
console.log('Pc')
},
willInsertElement: function () {
console.log('Pd')
}
});
非常感谢!