久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    1. <tfoot id='QiZFf'></tfoot>

    2. <small id='QiZFf'></small><noframes id='QiZFf'>

    3. <legend id='QiZFf'><style id='QiZFf'><dir id='QiZFf'><q id='QiZFf'></q></dir></style></legend>

    4. <i id='QiZFf'><tr id='QiZFf'><dt id='QiZFf'><q id='QiZFf'><span id='QiZFf'><b id='QiZFf'><form id='QiZFf'><ins id='QiZFf'></ins><ul id='QiZFf'></ul><sub id='QiZFf'></sub></form><legend id='QiZFf'></legend><bdo id='QiZFf'><pre id='QiZFf'><center id='QiZFf'></center></pre></bdo></b><th id='QiZFf'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='QiZFf'><tfoot id='QiZFf'></tfoot><dl id='QiZFf'><fieldset id='QiZFf'></fieldset></dl></div>
        <bdo id='QiZFf'></bdo><ul id='QiZFf'></ul>

      將本地文件中的 json 數(shù)據(jù)加載到 React JS 中

      loading json data from local file into React JS(將本地文件中的 json 數(shù)據(jù)加載到 React JS 中)

            <legend id='vb96g'><style id='vb96g'><dir id='vb96g'><q id='vb96g'></q></dir></style></legend>
            <i id='vb96g'><tr id='vb96g'><dt id='vb96g'><q id='vb96g'><span id='vb96g'><b id='vb96g'><form id='vb96g'><ins id='vb96g'></ins><ul id='vb96g'></ul><sub id='vb96g'></sub></form><legend id='vb96g'></legend><bdo id='vb96g'><pre id='vb96g'><center id='vb96g'></center></pre></bdo></b><th id='vb96g'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vb96g'><tfoot id='vb96g'></tfoot><dl id='vb96g'><fieldset id='vb96g'></fieldset></dl></div>
          1. <small id='vb96g'></small><noframes id='vb96g'>

              <tbody id='vb96g'></tbody>
            • <bdo id='vb96g'></bdo><ul id='vb96g'></ul>
              <tfoot id='vb96g'></tfoot>

              • 本文介紹了將本地文件中的 json 數(shù)據(jù)加載到 React JS 中的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我有一個 React 組件,我想從文件中加載我的 JSON 數(shù)據(jù).控制臺日志當(dāng)前不起作用,即使我將變量 data 創(chuàng)建為全局變量

                '使用嚴(yán)格';var React = require('react/addons');//從文件中加載 JSON 數(shù)據(jù)變量數(shù)據(jù);var oReq = new XMLHttpRequest();oReq.onload = reqListener;oReq.open("get", "data.json", true);oReq.send();函數(shù) reqListener(e) {數(shù)據(jù) = JSON.parse(this.responseText);}控制臺.log(數(shù)據(jù));var List = React.createClass({獲取初始狀態(tài):函數(shù)(){返回{數(shù)據(jù):this.props.data};},渲染:函數(shù)(){var listItems = this.state.data.map(function(item) {var eachItem = item.works.work;var photo = eachItem.map(function(url) {返回 (<td>{url.urls}</td>)});});返回 <ul>{listItems}</ul>}});var redBubble = React.createClass({渲染:函數(shù)(){返回 (

                <列表數(shù)據(jù)={數(shù)據(jù)}/></div>);}});module.exports = redBubble;

                理想情況下,我更愿意這樣做,但它不起作用 - 它會嘗試將 ".js" 添加到文件名的末尾.

                var data = require('./data.json');

                任何關(guān)于最佳方式的建議,最好是React"方式,將不勝感激!

                解決方案

                您正在打開一個 異步連接,但是您已經(jīng)編寫了代碼,就好像它是同步的一樣.reqListener 回調(diào)函數(shù)不會與您的代碼同步執(zhí)行(即在 React.createClass 之前),但只會在您的整個代碼段運行并收到響應(yīng)之后執(zhí)行從您的遠(yuǎn)程位置.

                除非您處于零延遲的量子糾纏連接上,否則在您的所有語句都運行之后,這是好吧.例如,要記錄接收到的數(shù)據(jù),您可以:

                函數(shù) reqListener(e) {數(shù)據(jù) = JSON.parse(this.responseText);控制臺.log(數(shù)據(jù));}

                我沒有在 React 組件中看到 data 的使用,所以我只能從理論上提出這個建議:為什么不在回調(diào)中更新您的組件?

                I have a React component and I want to load in my JSON data from a file. The console log currently doesn't work, even though I'm creating the variable data as a global

                'use strict';
                
                var React = require('react/addons');
                
                // load in JSON data from file
                var data;
                
                var oReq = new XMLHttpRequest();
                oReq.onload = reqListener;
                oReq.open("get", "data.json", true);
                oReq.send();
                
                function reqListener(e) {
                    data = JSON.parse(this.responseText);
                }
                console.log(data);
                
                var List = React.createClass({
                  getInitialState: function() {
                    return {data: this.props.data};    
                  },
                  render: function() {
                    var listItems = this.state.data.map(function(item) {
                        var eachItem = item.works.work;        
                
                        var photo = eachItem.map(function(url) {
                            return (
                                <td>{url.urls}</td> 
                            )
                        });
                    });
                    return <ul>{listItems}</ul>
                  }
                });
                
                var redBubble = React.createClass({
                    render: function() {
                      return (
                        <div>
                          <List data={data}/>          
                        </div>
                      );
                    }
                  });
                
                module.exports = redBubble;
                

                Ideally, I would prefer to do it something like this, but it's not working - it tries to add ".js" onto the end of the filename.

                var data = require('./data.json');
                

                Any advice on the best way, preferably the "React" way, would be much appreciated!

                解決方案

                You are opening an asynchronous connection, yet you have written your code as if it was synchronous. The reqListener callback function will not execute synchronously with your code (that is, before React.createClass), but only after your entire snippet has run, and the response has been received from your remote location.

                Unless you are on a zero-latency quantum-entanglement connection, this is well after all your statements have run. For example, to log the received data, you would:

                function reqListener(e) {
                    data = JSON.parse(this.responseText);
                    console.log(data);
                }
                

                I'm not seeing the use of data in the React component, so I can only suggest this theoretically: why not update your component in the callback?

                這篇關(guān)于將本地文件中的 json 數(shù)據(jù)加載到 React JS 中的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調(diào)用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調(diào)用完成)
                JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標(biāo)頭) - IT屋-程序員軟件開發(fā)技術(shù)分
                Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內(nèi)容)

                    <legend id='uBb4Y'><style id='uBb4Y'><dir id='uBb4Y'><q id='uBb4Y'></q></dir></style></legend>
                      <tbody id='uBb4Y'></tbody>
                    <tfoot id='uBb4Y'></tfoot>
                    <i id='uBb4Y'><tr id='uBb4Y'><dt id='uBb4Y'><q id='uBb4Y'><span id='uBb4Y'><b id='uBb4Y'><form id='uBb4Y'><ins id='uBb4Y'></ins><ul id='uBb4Y'></ul><sub id='uBb4Y'></sub></form><legend id='uBb4Y'></legend><bdo id='uBb4Y'><pre id='uBb4Y'><center id='uBb4Y'></center></pre></bdo></b><th id='uBb4Y'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='uBb4Y'><tfoot id='uBb4Y'></tfoot><dl id='uBb4Y'><fieldset id='uBb4Y'></fieldset></dl></div>
                      • <bdo id='uBb4Y'></bdo><ul id='uBb4Y'></ul>

                        <small id='uBb4Y'></small><noframes id='uBb4Y'>

                        • 主站蜘蛛池模板: 日韩激情视频一区 | 日日干天天操 | 91操操操 | 成人免费在线小视频 | 91豆花视频 | 欧美精品一二区 | 国产精品久久久久aaaa | 97日韩精品 | 久久99精品久久久久久青青日本 | 啪一啪 | 日韩图区 | 亚洲草草视频 | 亚洲日本欧美日韩高观看 | 精品少妇一区二区三区在线播放 | 91精品国产麻豆 | 中文字幕国产视频 | 国产美女精品 | 久视频在线观看 | 日韩精品一区二区三区视频播放 | 黄色国产在线视频 | 99视频网站 | 国产一级一级国产 | 久久久久久国模大尺度人体 | 亚州精品天堂中文字幕 | 毛片a| 中文字幕11页 | 国产第一页在线观看 | 最近日韩中文字幕 | 午夜免费观看网站 | 在线观看av网站永久 | 婷婷激情在线 | 超碰在线人 | www.久久国产精品 | 天天人人精品 | 欧美日韩一区在线观看 | 一级欧美黄色片 | 欧美极品在线观看 | 国产不卡在线观看 | 毛片a | 国产片侵犯亲女视频播放 | 欧美性极品xxxx做受 |