简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM