聚合物驼峰属性 [英] Polymer camelCase attributes

查看:148
本文介绍了聚合物驼峰属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写周围的聚合物组分一个JS库的包装。基本上,我需要能够将属性分配给组件,并将其转发到一个js对象的实例。

I'm writing a wrapper around a js library with Polymer components. Basically, I need to be able to assign attributes to a component, and forward them to an instance of a js object.

问题是,聚合物(或一般webcomponents?)力量属性名称小写。

The problem is that Polymer (or webcomponents in general?) forces attribute names to be lowercase.

声明元素

<有的元素foobar的=巴兹>< /有的-组件>

通用变化监听

attributeChanged: function(attrName, oldVal, newVal){
    // attrName -> foobar, which is not a member of someInstance
    this.someInstance[attrName] = newVal;
}

有一些办法让骆驼套管的名字吗?也许我可以从一个哈希发布的原型对象......但我怎么引用?

Is there some way to get the camel-cased name? Maybe I can create a hash from the publish object on the prototype... but how do I reference that?

推荐答案

啊哈! 发布是组件实例实际可用!这让我抢的名称和作出地图从小写字母大写。

Aha! publish is actually available on the component instance! This allows me to grab the names and make a map from lowercase to camelcase.

var map = {};
Object.keys(this.publish).forEach(function(key){
    map[key.toLowerCase()] = key;
});

这篇关于聚合物驼峰属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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