简体   繁体   中英

Iterate over SQLOBJECT -WEBSQL

I want to iterate over a SQLObject in javascript.I have some data in a WEBSQL database in the browser.

Until now I was rendering in React like this

var list = data.map(function(film){
    return <li key={film.ID}>
               {film.NAME}
            </li>;
  },this);

return (
  <div>
    <ul className="table-view">
      {list}
    </ul>
  </div>
);

However,I can't do this with this type of object.

How can I do it without putting the HTML inside string.

I want to avoid iterating with for then adding the results to a string object

You have to use map function to iterate and return Array of Components.

Alternate way is to use dangerouslyInsertedHTML or dangerouslySetHTML in div tag. You can check this how it can be done. You can use for Loop to iterate over the array of object and generate your HTML as string appended to the previous object. Click here !

Thanks, Ankit.

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