简体   繁体   English

如何在模型中设置基于Ember组件的数据的tagName?

[英]How to set the tagName of an Ember component based data in the model?

I would like to set the tagName of an ember component based on data in the model like this: 我想根据模型中的数据设置一个ember组件的tagName,如下所示:

App.TestComponent = Ember.Component.extend({
    tagName: function(){return this.get('tag');}.property('tag')
});

This doesn't work though. 但这不起作用。 The W3C specifies that you can't change the tagName of an element, so I can see why binding a variable to a static property would be problematic - just not sure how to accomplish this. W3C指定你不能改变元素的tagName,所以我可以看到为什么将变量绑定到静态属性会有问题 - 只是不知道如何实现这一点。

Any ideas? 有任何想法吗?

Use tagName 使用tagName

{{test-foo tagName=item}}

http://emberjs.jsbin.com/molamohi/1/edit http://emberjs.jsbin.com/molamohi/1/edit

http://emberjs.jsbin.com/vowur/3/edit shows how to set the tagName of a Component based on a property in a model object. http://emberjs.jsbin.com/vowur/3/edit显示了如何根据模型对象中的属性设置Component的tagName Specifically: 特别:

{{test-component someVal=model.val tagName=model.tag}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM