我正在研究实现自定义数据网格,但希望将数据作为自定义元素的内容提供内联:
<x-datagrid>
<row>
<col>Value 1</col><col>Value 2</col>
</row>
</x-datagrid>
你可以清楚地实现这一点,因为菜单和标签元素基于此填充......虽然如何完成?我查看了core-downdown菜单的组件源:
https://github.com/Polymer/core-dropdown-menu/blob/master/core-dropdown-menu.html
不要告诉我多少......我还能看到其他什么?
答案 0 :(得分:0)
我可以使用Polymer.dom(this)
函数中的ready
执行此操作。
一个示例,它将子<option>
元素中的数据加载到组件的data
属性中:
ready: function() {
var self = this; // Since "this" gets lost in the forEach
Polymer.dom(this).querySelectorAll('option').forEach(function(opt) {
self.push('data', {id: opt.value, text: opt.textContent});
});
},
我的组件看起来像:
<my-component>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</my-component>