草庐IT

all_children

全部标签

javascript - react : Why is `this.props.children` undefined?

我正在使用ReactJS构建电子电阻计算器。我有一个这样声明的组合组件:varResistanceCalculator=React.createClass({getInitialState:function(){return{bands:[0,0,0,0,0]}},componentDidMount:function(){console.log(this.props.children);//=>undefined},render:function(){return();}});BandSelector呈现元素和当一个改变时我想更新ResistanceCalculator的状态。所以我的

javascript - AngularJS $q.all 和多个 $q.defer

即使我已经设法让我的代码工作,但还是有一些我不明白的地方。以下代码段功能正常:socket.on('method',function(){varpayload={countrycode:'',device:''};vard1=$q.defer();vard2=$q.defer();$q.all([geolocation.getLocation().then(function(position){geolocation.getCountryCode(position).then(function(countryCode){payload.countrycode=countryCode;d

javascript - Async/Await 无法按预期使用 Promise.all 和 .map 函数

我有很多正在使用的async函数,但我遇到了一个奇怪的问题。我的代码,工作,看起来像:asyncmainAsyncFunc(metadata){letfiles=metadata.map(data=>this.anotherAsyncFunc(data.url));returnPromise.all(files);}anotherAsyncFunc函数如下所示:asyncanotherAsyncFunc(url){returnawaitaxios({url,}).then(res=>res.data).catch(err=>{throwerr;});}当我尝试将更多数据附加到第一个函数

javascript - ReactJS - React.Children.forEach - 我可以获得子组件名称吗?

我有一个包含许多子项的React(15.5.4)组件,其中一些是HTML元素,一些是其他React组件。我正在使用服务器渲染并且需要在服务器和客户端上有相同的行为。客户端将使用React的生产构建。我需要遍历子组件并确定特定类型的React组件。所以我的第一个想法是使用React.Children.forEach()进行迭代并查找组件名称。React.Children.forEach(this.props.children,child=>{console.log('name=',child.name)})似乎child.name和child.displayName不存在。现在,chil

javascript - 为什么 JavaScript 的 `Promise.all` 没有在失败条件下运行所有​​ promise ?

根据MDN:Ifanyofthepassedinpromisesrejects,theallPromiseimmediatelyrejectswiththevalueofthepromisethatrejected,discardingalltheotherpromiseswhetherornottheyhaveresolved.ES6spec似乎证实了这一点。我的问题是:为什么Promise.all会在其中任何一个拒绝时丢弃promises,因为我希望它等待“所有”promises结算,并且“丢弃”到底是什么意思?(很难说出“丢弃”对于进行中的promises和可能尚未运行的prom

javascript - React.children.only 期望接收单个 react 元素子 Navigator

我尝试了太多主题帮助,但这并不能帮助我修复这个错误,也许是因为我是react-native的新手。这是给出错误的代码。render(){return(Navigator.SceneConfigs.FloatFromBottom}renderScene={RouteMapper}/>);}“React.children.onlyexpectedtoreceiveasinglereactelementchild”我在运行时收到此错误。请帮忙。我知道有很多其他类似的主题发布,但没有一个能为我的问题提供适当的解决方案。 最佳答案 react

javascript - Bootstrap Collapse - Jquery "Collapse all"函数

我正在前端使用Bootstrap编写一个个人提要阅读器,并想添加一个“折叠/全部展开”按钮。这是我的第一个JavaScript/JQuery代码,所以除了在FirefoxDeveloperConsole中打印变量外,我不知道如何调试它。我的页面结构由面板组成。用户可以通过单击面板标题来展开或折叠面板。以及一个用于折叠或展开所有面板的按钮。我的解决方案大部分时间都有效,但我注意到一个奇怪的行为。这是我重现问题的方法:第一次打开页面通过单击标题展开一个面板现在折叠所有按钮折叠打开的面板,并展开其他面板。就好像它“切换”所有面板而不是关闭它们一样。在这种奇怪的行为之后,一切正常,如果不刷新页

javascript - JavaScript : How to get resolve value for all promises? 中的 Promise.all

我编写了以下node.js文件:varcsv=require('csv-parser');varfs=require('fs')varPromise=require('bluebird');varfilename="devices.csv";vardevices;Promise.all(read_csv_file("devices.csv"),read_csv_file("bugs.csv")).then(function(result){console.log(result);});functionread_csv_file(filename){returnnewPromise(fu

javascript - 在 react 中将值传递给子组件(this.props.children)

我在布局中有一个子组件,我也想传递一个Prop值。但我不知道怎么办。在下面的类中,layoutFileDataRequest()在单击事件时从子组件接收字符串变量。需要将该值发送到this.props.children组件之一,以便它可以更新。我该怎么做?在下面的代码中React.cloneElement(child,{不会改变它总是保持不变,这意味着我无法更新child属性。exportdefaultclassLayoutextendsReact.Component{constructor(props){super(props)this.layoutFileDataRequest=t

javascript - react : Use this. props.children 或将组件作为命名 Prop 传递

我正在构建一个需要渲染一些子组件的组件。更具体地说,我有一个map组件,我希望在其上显示一个图例组件。constMap=props=>({this.props.children});//Usage:constMapWithLegend=()=>();//Usage:constMapWithoutLegend=()=>();然而,这也可以用命名Prop来表达:constMap=({legend}=>({legend});//Usage:constMapWithLegend=()=>();//Usage:constMapWithoutLegend=()=>();我不确定哪种方式在扩展性和可