ã¯ã¦ãªããã°ã®feedãjsonã§åå¾ãã¦Reactã§è¡¨ç¤ºãã¦ã¿ã with YQL
åè¨äºã§ã¯ãã¯ãã¹ãã¡ã¤ã³ãªã¯ã¨ã¹ãã«ã¤ãã¦å¦ã³ã¾ãããããããæ®éã«CORSãè¡ã£ã¦ããNo 'Access-Control-Allow-Origin' header is present on the requested resourceã¨è¿ãããAPIãããã¾ããã»ãã¥ãªãã£ã®åé¡ããAPIã許å¯ãã¦ããªãããã§ãã
ã¯ã©ã¤ã¢ã³ãã®æä½ã®ã¿ã§ç°¡åã«åå¾ã§ããªãããªãã¨æ¢ãã¦ããã¨ããããªãã©ã°ã¤ã³ãããã¾ããã
ãããç¨ããã¨ãã¯ãã¹ãã¡ã¤ã³ã®GETãªã¯ã¨ã¹ããå¯è½ã«ãªãã¿ããã§ããä»çµã¿ã¯ã©ããªã£ã¦ããã®ãã¨ããã¨ãYQLã®APIã使ç¨ãã¦ãã¾ãã
YQL consoleã使ç¨ãã¦feedãã¼ã¿ã確èªãã
ã¾ãã¯YQL consoleãéãã¦ãdata>feedããfeedåå¾ã®ã·ã³ã¿ãã¯ã¹ã確èªãSQLãå¦ç¿ãããã¨ããããªãèºããã¨ã¯ãªãããã§ããã
YOUR YQL STATEMENTã®ãã£ã¼ã«ãã«YQLãå ¥åãã¾ããurlã®å¤ãåå¾å ã®feed URLã«å¤æ´ãä»åã¯å ¨é¨(*)åå¾ããå¿ è¦ããªãã®ã§ãtitleã®ã¿åå¾ã«ãtestãã¿ã³ãæ¼ãã¨ãçµæãããã£ã¨ä¸¦ã³ã¾ãã
jQuery.ajaxã¨YQLãåããã¦ã¿ã
Tree Viewãè¦ãªãããjQueryã¨çµã¿åããã¦ã¿ã¾ãããã次ã®ãããªãªã¯ã¨ã¹ããè¨è¿°ã§ãã¾ãã
$.ajax({ // Set YQL URL url: "http://query.yahooapis.com/v1/public/yql?callback=?", data: { // YQL statement q: "select title from feed where url = 'http://uraway.hatenablog.com/feed'", // XML or JSON format: "json" }, type: 'GET', dataType: 'json', success: function(res) { for (var i in res.query.results.entry) { console.log(res.query.results.entry[i].title); } }, error: function(xhr, status, err) { console.log(status, err.toString()); } }); }
React + ajax
ä¸è¨ã®ãªã¯ã¨ã¹ããReactã®ã³ã³ãã¼ãã³ãã«å ¥ãã¦ã¿ã¾ãããã¨ããããã¯ã¿ã¤ãã«ã表示ããã ãã§ããã
åè: dynamic-children
JSONãã¼ã¿ãYQLãéãã°åå¾ã§ããã¯ããå¾ã§ãã£ã¨ããã