javascriptpolymeriron-ajax

Dealing with text/plain in iron-ajax and dom-repeat


I have an API which unfortunately returns text/plain elements. Although the output format is JSON, the mime type is text/plain.

When using iron-ajax to request output from the API, I can store the output in a String called response. However, I cannot iterate through the output, which is a list of json objects of the like

[ {"userid": 1, "name": "testuser"}, {"userid": 2, "name": "testuser 2"}]

since dom-repeat complains that this object is not an array.

I tried to dom-repeat using certain additional function, for example:

<template is="dom-repeat" items="{{response.values()}}">

or

<template is="dom-repeat" items="{{Array.from(response)}}">

but these functions return nothing. How can I deal with my text/plain data in dom-repeat?


Solution

  • If you received the response in String format you may convert to JSON.Parse(string) and the format you provided above is exacly format which dom-repeat needs.

    here this below link, you may check. (You can even debug the console)

    DEMO