您如何为sproutcore / emberjs内嵌脚本模板指定标签名称? [英] How do you specify the tag name for sproutcore/emberjs inline script templates?

查看:129
本文介绍了您如何为sproutcore / emberjs内嵌脚本模板指定标签名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ember内联模板包裹在DIV中。我想用不同的标签包装它们。如何做?

Ember inline templates are wrapped in DIVs. I'd like to wrap them with a different tag. How do I do that?

以下模板:

<script type="text/x-handlebars">
Foo
</script>

生成如下内容:

<div>Foo</div>

我想生成如下内容:

<someOtherTag>Foo</someOtherTag>


推荐答案

我不认为这是可能的版本0.9.3。如果您查看 https ://github.com/emberjs/ember.js/blob/master/packages/ember-views/lib/views/view.js#L707 div 属性 tagName 未设置时使用。

I don't think that is possible in the current version 0.9.3 . If you look at https://github.com/emberjs/ember.js/blob/master/packages/ember-views/lib/views/view.js#L707 div is used when the property tagName is not set.

您可以定义自己的 Ember .View 并设置tagName,但是我想您不需要创建自己的视图类即可实现此目的。

You could define your own Ember.View and set the tagName but I guess you want to achieve this without creating your own view class.

更新

我通过在脚本元素上指定您的自定义视图为 data-view 属性找到了一种方式。 p>

I found a way via specifying your custom view as data-view attribute on the script element.

<head>
    <script type="text/javascript" >
        App = Ember.Application.create({});
        App.View = Ember.View.extend({
            tagName: 'someOtherTag'
        });
    </script>
</head>
<body>
    <script type="text/x-handlebars" data-view="App.View" >
        Foo
    </script>
</body>

请参阅 http://jsfiddle.net/9F7kR/2/

这篇关于您如何为sproutcore / emberjs内嵌脚本模板指定标签名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆