本文介绍了如何解决Embers Handlebar和Django模板之间的冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ember和Django,并很快发现Handlebar中的模板分隔符与Django模板的模板分隔符相冲突。



所以我想象Django-embers



但它似乎不能正常工作。这是问题:



如果我在APP.js中有这样的东西

  var Ab = Em.Application.create({
appDescription:'HelloWorldApp'
});

我可以轻松地在模板中呈现这样的

  {%load ember%} 
{%handlebars%}
{{Ab.appDescription}}
{%endhandlebars%}

这个工作。
但是当我尝试使用模板标签,例如{{#each}}事情失败。例如我在APP.js中有这样的

  Songs.songsController = Ember.ArrayController.create({
content: [],
init:function(){
//创建一个Song模型的实例
var song = Songs.Song.create({
title:'Son of the 'b







$ b});

并尝试使用以下功能:

  {%load ember%} 
{%handlebars%}
{{#each Songs.songsController}}
< h3&标题}}< / H3>
< p> {{artist}} - {{genre}}< / p>
{{/ each}}
{%endhandlebars%}

输出!



它与我的代码无关,因为我移动了模板和JS文件外部django并测试了代码,它的工作原理如下。 >

请告诉这里发生什么问题!

解决方案

init function是所有Ember对象的构造函数。基本上,为了在创建对象时将所有绑定/观察者的东西放在一起,覆盖引用者时,必须调用类层次结构的构造函数。其实这就像你在其他编程语言中一样。


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!

解决方案

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.

这篇关于如何解决Embers Handlebar和Django模板之间的冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 04:37