为了在隔离环境中测试我的一些聚合物自定义元素,我希望能够传递JavaScript对象字面量作为一些属性的值,而这些属性通常是来自父元素。但我无法弄清如何实现这一点。请看以下示例代码。如果它按照我的期望工作,它会将1和2并排显示,但它并没有正常工作。
<script src="http://www.polymer-project.org/webcomponents.js"></script>
<link rel="import" href="http://www.polymer-project.org/components/polymer/polymer.html">
<polymer-element name="my-element" attributes="stuff">
<template>
{{stuff.one}} {{stuff.two}}
</template>
<script>
Polymer('my-element', {
ready: function () {
console.log(this.stuff);
}
});
</script>
</polymer-element>
<my-element stuff='{"one": 1, "two": 2}'></my-element>