Verbose Logging in Ember

2019-05-24 23:02发布

I'm trying to wrap my head around Ember at the moment, but all the magic is making this difficult.

I've set LOG_TRANSITIONS: true and Ember.LOG_BINDINGS = true; which gives me some minimal logging to the console, but I really need more than that.

I'm particularly struggling with seeing what's going on when Ember is automagically creating Controllers, Views and Templates.

Is there a way to log this aspect of the framework - to see where Ember is looking for Templates/Views/Controllers and when it is creating one on its own volition.

For example, I have the following routes set up:

App.Router.map(function() {

  this.route("example_items", {path: "/"});

});

with:

App.ExampleItemsRoute = Ember.Route.extend({
  model: function() {
    return App.ExampleItem.find();
  }

});

Ember renders my ApplicationController and its application.handlebars template:

<header class="page-header">
  <h1>Application Template</h1>
</header>
{{outlet}}

But fails to render my example_items.handlebars template. I get no exception or warning, and if I check the DOM, I can see ember has created a generic view in its place.

The bindings logging shows me that Ember has transitioned to example_items, but it seems it hasn't used either my ExampleItemsController, ExampleItemsView or template.

How can I debug a situation like this if I receive no errors or messages?

Edit:

App.ExampleItems View:

App.ExampleItemsView = Ember.CollectionView.extend({
  templateName: 'example_items'
});

And App.ExampleItemsController:

App.ExampleItemsController = Ember.ArrayController.extend({

});

2条回答
叼着烟拽天下
2楼-- · 2019-05-24 23:34

I'm particularly struggling with seeing what's going on when Ember is automagically creating Controllers, Views and Templates.

Is there a way to log this aspect of the framework - to see where Ember is looking for Templates/Views/Controllers and when it is creating one on its own volition.

Yes. With the latest ember you can now LOG_ACTIVE_GENERATION to see console.log output whenever ember generates something for you.

Another new setting that might be helpful is LOG_VIEW_LOOKUPS

查看更多
▲ chillily
3楼-- · 2019-05-24 23:37

Here's your problem: CollectionView won't use your template. It takes an array as its content property (usually set up as a binding to the controller) and creates childViews manually. Without a content set it'll appear as a blank view.

If you add classNames: ['my-view'] to your view definition, you should see that the view it's instantiating and inserting is actually your view class, just empty. Add contentBinding: 'controller' and it should render itemViews for each item in the array, as well.

查看更多
登录 后发表回答