pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    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="g02iky2" id='QiZFf'><tfoot id='QiZFf'></tfoot><dl id='QiZFf'><fieldset id='QiZFf'></fieldset></dl></div>
        <bdo id='QiZFf'></bdo><ul id='QiZFf'></ul>

      將本地文件中的 json 數據加載到 React JS 中

      loading json data from local file into React JS(將本地文件中的 json 數據加載到 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="8ckm202" 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 數據加載到 React JS 中的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

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

                '使用嚴格';var React = require('react/addons');//從文件中加載 JSON 數據變量數據;var oReq = new XMLHttpRequest();oReq.onload = reqListener;oReq.open("get", "data.json", true);oReq.send();函數 reqListener(e) {數據 = JSON.parse(this.responseText);}控制臺.log(數據);var List = React.createClass({獲取初始狀態:函數(){返回{數據:this.props.data};},渲染:函數(){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({渲染:函數(){返回 (

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

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

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

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

                解決方案

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

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

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

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

                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?

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

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

                相關文檔推薦

                Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                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標頭) - IT屋-程序員軟件開發技術分
                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 部分內容)

                    <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="ycsmeks" 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'>

                        • 主站蜘蛛池模板: 书信之家_书信标准模板范文大全| 根系分析仪,大米外观品质检测仪,考种仪,藻类鉴定计数仪,叶面积仪,菌落计数仪,抑菌圈测量仪,抗生素效价测定仪,植物表型仪,冠层分析仪-杭州万深检测仪器网 | C形臂_动态平板DR_动态平板胃肠机生产厂家制造商-普爱医疗 | 复合肥,化肥厂,复合肥批发,化肥代理,复合肥品牌-红四方 | 振动台-振动试验台-振动冲击台-广东剑乔试验设备有限公司 | 车牌识别道闸_停车场收费系统_人脸识别考勤机_速通门闸机_充电桩厂家_中全清茂官网 | 粤丰硕水性环氧地坪漆-防静电自流平厂家-环保地坪涂料代理 | 无味渗透剂,泡沫抑尘剂,烷基糖苷-威海威能化工有限公司 | 冷却塔改造厂家_不锈钢冷却塔_玻璃钢冷却塔改造维修-广东特菱节能空调设备有限公司 | 缓蚀除垢剂_循环水阻垢剂_反渗透锅炉阻垢剂_有机硫化物-郑州威大水处理材料有限公司 | 识禅_对禅的了解,从这里开始 | 无缝方管|无缝矩形管|无缝方矩管|无锡方管厂家 | 木材烘干机,木炭烘干机,纸管/佛香烘干设备-河南蓝天机械制造有限公司 | 特材真空腔体_哈氏合金/镍基合金/纯镍腔体-无锡国德机械制造有限公司 | 闪电优家-卫生间防水补漏_酒店漏水渗水维修_防水堵漏公司 | 膏方加工_丸剂贴牌_膏滋代加工_湖北康瑞生物科技有限公司 | 皮带机-带式输送机价格-固定式胶带机生产厂家-河南坤威机械 | 广州昊至泉水上乐园设备有限公司| 对照品_中药对照品_标准品_对照药材_「格利普」高纯中药标准品厂家-成都格利普生物科技有限公司 澳门精准正版免费大全,2025新澳门全年免费,新澳天天开奖免费资料大全最新,新澳2025今晚开奖资料,新澳马今天最快最新图库 | 识禅_对禅的了解,从这里开始 | 山东led显示屏,山东led全彩显示屏,山东LED小间距屏,临沂全彩电子屏-山东亚泰视讯传媒有限公司 | 垃圾处理设备_餐厨垃圾处理设备_厨余垃圾处理设备_果蔬垃圾处理设备-深圳市三盛环保科技有限公司 | 不锈钢监控杆_监控立杆厂家-廊坊耀星光电科技有限公司 | 沈阳缠绕膜价格_沈阳拉伸膜厂家_沈阳缠绕膜厂家直销 | 范秘书_懂你的范文小秘书| 塑钢课桌椅、学生课桌椅、课桌椅厂家-学仕教育设备首页 | 校服厂家,英伦校服定做工厂,园服生产定制厂商-东莞市艾咪天使校服 | 浙江自考_浙江自学考试网 | 礼仪庆典公司,礼仪策划公司,庆典公司,演出公司,演艺公司,年会酒会,生日寿宴,动工仪式,开工仪式,奠基典礼,商务会议,竣工落成,乔迁揭牌,签约启动-东莞市开门红文化传媒有限公司 | 全自动烧卖机厂家_饺子机_烧麦机价格_小笼汤包机_宁波江北阜欣食品机械有限公司 | 语料库-提供经典范文,文案句子,常用文书,您的写作得力助手 | 苏州教学设备-化工教学设备-环境工程教学模型|同科教仪 | 测试治具|过炉治具|过锡炉治具|工装夹具|测试夹具|允睿自动化设备 | 铝镁锰板_铝镁锰合金板_铝镁锰板厂家_铝镁锰金属屋面板_安徽建科 | 电伴热系统施工_仪表电伴热保温箱厂家_沃安电伴热管缆工业技术(济南)有限公司 | 润东方环保空调,冷风机,厂房车间降温设备-20年深圳环保空调生产厂家 | 执业药师报名时间,报考条件,考试时间-首页入口 | 广东恩亿梯电源有限公司【官网】_UPS不间断电源|EPS应急电源|模块化机房|电动汽车充电桩_UPS电源厂家(恩亿梯UPS电源,UPS不间断电源,不间断电源UPS) | 直读光谱仪,光谱分析仪,手持式光谱仪,碳硫分析仪,创想仪器官网 | 车牌识别道闸_停车场收费系统_人脸识别考勤机_速通门闸机_充电桩厂家_中全清茂官网 | 瓶盖扭矩测试仪-瓶盖扭力仪-全自动扭矩仪-济南三泉中石单品站 |