Should attributes be passed to objects?

When I pass values ​​to the attribute of the polymer element, I can pass the object through Polymer data binding. However, if I decide to leave the "polymer land" and want to set the attribute of the object, I cannot. Should I pass objects into attributes?

If the answer is “no, you should use methods for this,” the next question will be: “Can I call an elemental method without being within the Polymer?” For example, if I have a polymer element:

<hello></hello>

and I want to access a method that he called the "world." In Polymer, this will be:

this.$.hello.world();

Is it possible to call this method without defining the Polymer element?

+3
source share
2 answers

Inside Polymer

, 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

Polymer / , :

<hello-world persons="[{'name': 'Eric'}, {'name': 'Bob'}]"></hello-world>

.persons , JS:

document.querySelector('hello-world').persons = [{'name': 'Eric'}, {'name': 'Bob'}];
+8

, .

, . , .

, .

document.querySelector('hello').world();

, , .

-Jay

+1

All Articles