-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unclear how to bind complex data objects to new instances of polymer-element as a passed-in attribute #488
Comments
I can't figure out what your example is doing because you transformed the syntax using CoffeeScript and whatever 'haml' is. Posting a JSBin using canonical syntax will get you a much more effective response. Here is an example: http://jsbin.com/xumiqolu/3/edit |
Okay, I've created a pen that allows you to view the code as plain 'ol |
Actual running examples are superior, afaict, you are just sending source. In any case, |
I should have done the following instead instead? this.supermodel = {
name: this.name
} That's what I thought until My |
There is some basic misunderstanding, but I cannot tell what it is you are trying to achieve. My first JSBin was not helpful? Here is another try: http://jsbin.com/xumiqolu/3/edit It's much easier to discuss in terms of a working example. |
Your example definitely clears things up a bit except the attributes part that has me a bit stumped. I'm trying to be able to set the <x-supermodel name="Kate Upton"></x-supermodel> Another element (beer-item) was supposed to demonstrate this what I'm trying to accomplish is the following code below, but it doesn't work (from Web Components in Action): index.html <polymer-element name="beer-item"
attributes="beerName imageUrl pints beer">
<template>
<div class="beer">
<img src="{{beer.imageUrl}}">
<span>{{beer.beerName}}</span>
<div>{{beer.pints}} pints tasted so far</div>
</div>
</template>
<script src="beer_item.js>
</polymer-element>
beer_item.js var beerApp = beerApp || {};
beerApp.BeerItem = function(beerName, imageUrl, pints) {
this.beerName = beerName || '';
this.imageUrl = imageUrl || 'beer.png';
this.pints = pints || 0;
};
Polymer('beer-item', {
created: function() {
this.beer = new BeerItem(this.beerName || '',
this.imageUrl || '',
this.pints || 0);
} }); |
The attributes map directly to properties. You can set Here are some more examples: All the attributes are distinct, there is no automatic mapping of |
Understood, it's now a whole lot clear to me now to accomplish what I wanted from I can't thank you enough for the detailed examples (especially considering the fact it's Friday). The reference material I've provided must be using an older version of Polymer or something then. I'll immediately notify the author. |
Great, that's what we're here for. Don't hesitate to post more questions. |
The Problem
There seems to be an issue binding complex objects w/ Polymer than what I'm familar with. I'm using the latest version of
polymer
, as well asplatform.js
.What I mean by 'complex objects'
I'm familiar creating web components natively that can bind to complex objects as the model it supports as shown below:
index.html
main.coffee
*Of course, this is not enough since I would have create a prototype for the new element that inherits from
HTMLElementPrototype
anddocument.register
to register thex-supermodel
element as a valid element instead ofHTMLUnknownElement
*Detailed explanation of the problem
With the latest version of Polymer, creating elements for basic types is straightforward as always:
index.haml
supermodel_basic.coffee (works)
However, the following should work, but doesn't when attempting to bind a complex object:
index.haml
supermodel.coffee (doesn't work)
According to Chris Buckett (author of Web Components in Action), this pattern should work to bind a complex object & instances of
polymer-element
together. Did the latest version(s) of Polymer change the way complex objects can be binded as a model?The text was updated successfully, but these errors were encountered: