javascript - How would you create new elements based on an ajax query after initial load in Reactjs? -
i new using react.js. in theory, looks pretty neat, i'm having rethink how solve simple problems used solving jquery. 1 of how generate components dynamically after initial load based on user input.
let's have <searchbox />, , want user able enter query, click search, , generate arbitrary number of <searchresult /> components, based upon results of ajax call. assume create update method attached searchbox called onclick grab data, how go dynamically rendering searchresult components after each search once data arrives?
i suppose looking along lines of angular's ng-repeat directive, i'm not seeing effect in react.
i wrong think simple as:
... render: function() { var length = data.length; // data contains result received ajax var searchresultobjects = []; (var = 0; < length; += 1) { searchresultobjects[searchresultobjects.length] = <searchresult />; } return ( <ul> {searchresultobjects} // assuming searchresult object returns <li> item render function </ul> ); } ... and here example of that.
update:
take @ updated fiddle example of updating results , observe events in console window of developer tools of browser. hope clarifies.
Comments
Post a Comment