Hi,

I try to get sample data from a JSON file to fill my template with 
repeatable elements based on the original tutorial (with post-service) and 
the new sample on the 1.0 homepage (friend-list).
My JSON looks like that:

[
  {
    "address": {
      "Value": "ip:port",
      "Generation": xyz,
      "Version": 123
    },
    "alive": {
      "Value": "false",
      "Generation": xyz,
      "Version": 123 
    },
    "name": {
      "Value": "foo",
      "Generation": xyz,
      "Version": 123
    },
    "version": {
      "Value": "2015.06.01.009",
      "Generation": xyz,
      "Version": 123
    }
  }
]


Now I tried to create a data-provider (like post-service from first 
tutorial) in the following way

<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-ajax/iron-ajax.html">
<polymer-element name="data-provider" attributes="states">
      <iron-ajax
         auto
         url="application-states.json"
         last-response="{{statesLoaded}}"
         handleAs="json"
         debounce-duration="300"
         verbose="true">
      </iron-ajax>
  </template>
  <script>
Polymer('data-provider', {
  created: function() {
    this.states = [];
  },
  statesLoaded: function() {
    // Make a copy of the loaded data
    this.states = this.$.ajax.response.slice(0);
  },
});
</script>


and my custom element which uses the provider

<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="data-provider.html">

<dom-module id="application-states">
  <template>
     <template is="dom-repeat" items="{{states}}">
        <application-state name="{{item.address}}"
                           value="{{item.value}}"
                           generation="{{item.generation}}"
                           version="{{item.version}}">
        </application-state>
      </template>
  </template>


Unfortunately I get the following JS error, when previewing the element 
with polyserve.

mutating the [[Prototype]] of an object will cause your code to run very 
slowly; instead create the object with the correct initial [[Prototype]] 
TypeError: prototype.registerCallback is not a function

Any suggestions?

Thx in advance

Am Sonntag, 10. Mai 2015 22:51:51 UTC+2 schrieb Thad Humphries:
>
> I can use iron-ajax with Polymer 0.9.0-rc1 to retrieve a JSON object and 
> display a value in the template like so:
>
> <dom-module id="my-element">
>   <template>
>     <iron-ajax url="
> http://api.openweathermap.org/data/2.5/weather?type=accurate&units=imperial&cnt=1&q=Charlottesville
> "
>
> auto last-response="{{resp}}"></iron-ajax>
>
>     <textarea value="{{resp.main.temp}}"></textarea>
>   </template>
> </dom-module>
>
> <script>
>   Polymer({
>     is: 'my-element',
>     properties: {
>       resp: { 
>         type: Object 
>       } 
>     }
>   });
> </script>
>
>
> This also works with a simple JSON object retrieved from a public HTML 
> directory on my localhost. However I try to access an object in an array, 
> I'm told the object is undefined. For example, if the JSON array contains 
> two objects called "queries", <textarea 
> value="{{resp.queries}}"></textarea> displays "[object Object],[object 
> Object]". However if I attempt, <textarea 
> value="{{resp.queries[0]}}"></textarea> or <textarea 
> value="{{resp.queries[0].title}}"></textarea>, the displayed value is "
> undefined".
>
> Am I doing something wrong? Is this a known shortcoming? Is there a work 
> around?
>

Follow Polymer on Google+: plus.google.com/107187849809354688692
--- 
You received this message because you are subscribed to the Google Groups 
"Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/polymer-dev/37e32139-b4fb-498d-8a91-4d6f2cfe2b1f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to