Polymer 属性应该传递给对象吗?
当我将值传递给polymer元素属性时,我可以通过polymer的数据绑定传递对象。但是,如果我决定离开“polymer land”并想将属性设置为对象,我就不能。我应该将对象传递到属性中吗 如果答案是“否,您应该使用方法” 接下来的一个问题是,“我能调用一个元素的方法而不在聚合物框架中吗?”例如,如果我有一个聚合物元素:Polymer 属性应该传递给对象吗?,polymer,Polymer,当我将值传递给polymer元素属性时,我可以通过polymer的数据绑定传递对象。但是,如果我决定离开“polymer land”并想将属性设置为对象,我就不能。我应该将对象传递到属性中吗 如果答案是“否,您应该使用方法” 接下来的一个问题是,“我能调用一个元素的方法而不在聚合物框架中吗?”例如,如果我有一个聚合物元素: <hello></hello> 有没有可能在没有聚合物元素定义的情况下调用此方法?来回答我自己的问题 我认为属性不应该被传递给对象。如果需要将对象传
<hello></hello>
有没有可能在没有聚合物元素定义的情况下调用此方法?来回答我自己的问题 我认为属性不应该被传递给对象。如果需要将对象传递到元素中,请使用元素方法 要调用方法,可以使用简单的元素选择和方法调用
document.querySelector('hello').world();
我以为我已经试过了,但没用
-Jay来自内部聚合物
正如您所指出的,在Polymer内部,可以使用数据绑定将对象绑定到发布的属性:
<polymer-element name="other-el">
<template>
<hello-world persons="{{persons}}"></hello-world>
</template>
<script>
Polymer('other-el', {
created: function() {
this.persons = [{'name': 'Eric'}, {'name': 'Bob'}];
}
});
</script>
</polymer-element>
<polymer-element name="other-el">
<template>
<hello-world persons="{{persons}}"></hello-world>
</template>
<script>
Polymer('other-el', {
created: function() {
this.persons = [{'name': 'Eric'}, {'name': 'Bob'}];
}
});
</script>
</polymer-element>
<hello-world persons="[{'name': 'Eric'}, {'name': 'Bob'}]"></hello-world>
document.querySelector('hello-world').persons = [{'name': 'Eric'}, {'name': 'Bob'}];