问题
I am using Ember and Django and quickly found out that the template delimiter in Handlebar conflicts with that of Django Templates.
So i intsalled Django-embers http://pypi.python.org/pypi/django-ember/0.1
But It just not seem to work properly. This is the problem:
If I have something like this in APP.js
var Ab = Em.Application.create({
appDescription : 'HelloWorldApp'
});
I can easily render it in the template like this
{% load ember %}
{% handlebars "" %}
{{Ab.appDescription}}
{% endhandlebars %}
This works. But when I try using the Template Tags eg {{#each}} things fail. For example I had this in APP.js
Songs.songsController = Ember.ArrayController.create({
content: [],
init: function(){
// create an instance of the Song model
var song = Songs.Song.create({
title: 'Son of the Morning',
artist: 'Oh, Sleeper',
genre: 'Screamo'
});
this.pushObject(song);
}
});
And try to Rendeer it with:
{% load ember %}
{% handlebars "" %}
{{#each Songs.songsController}}
<h3>{{title}}</h3>
<p>{{artist}} - {{genre}}</p>
{{/each}}
{% endhandlebars %}
Nothing gets outputed!
And it has nothing to do with my code because I moved the template and JS file outsite django and tested the code, it works as expected then.
Do tell what is going wrong here!
回答1:
The init
function is the constructor of all Ember objects. Basically, in order to put in place all bindings/observers stuff when creating an object, the constructors of the class hierarchy must be called when overriding the contructor. In fact, this is just like you will do it in others programming languages.
来源:https://stackoverflow.com/questions/13357697/how-to-resolve-conflict-between-embers-handlebar-and-django-template