草庐IT

winfo_children

全部标签

javascript - Svelte 等同于 React 的 props.children?

我在svelte3的任何地方都找不到这个功能。我希望它是这样的..App.svelteCan'tconnecttotheserver!`Error.svelte{props.children}我希望App.svelte显示:Can'tconnecttotheserver!我只知道如何使用React的props.children来做到这一点。 最佳答案 您可以使用slot.它是svelte提供的一个组件。您可以在您的组件中使用它。传递给组件的任何内容都将代替插槽呈现在你的error.svelte中试试这个

javascript - react : How to access refs in this. props.children

我想调用一个子组件的函数。是否有可能在React中从this.props.children获取引用。varComponentSection=React.createClass({componentDidMount:function(){//Howtoaccessrefsinthis.props.children?this.refs.inner.refs.specificPanel.resize();},render:function(){return({this.props.children});}});varPanel=React.createClass({resize:functi

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 - 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 - React.children.only 期望接收单个 react 元素子 Navigator

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

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=()=>();我不确定哪种方式在扩展性和可

javascript - 是否可以在不渲染的情况下深度遍历 React Children?

有没有办法获取所有的bar中的属性在“静态”下方,例如没有渲染?importReactfrom'react';importReactDOMfrom'react-dom';classFooextendsReact.Component{render(){return(//wanttocollectthis'bar'//wanttocollectthis'bar';);}}classFooTupleextendsReact.Component{render(){return(;);}}classWrapperextendsReact.Component{render(){React.Chil

javascript - $ ('.className > button' ) 和 $ ('.className' ).children ('button' ) 有区别吗?

在jQuery中有什么区别$('.className>button')和$('.className').children('button')或者这些只是获得相同结果的替代语法? 最佳答案 不是说你最终会得到什么,但第一个可以完全卸载到浏览器的内置CSS选择引擎,而第二个需要jQuery做更多的工作并涉及更多的对象创建和清理。除非你在一个mousemove处理程序中使用很多元素来做这件事,否则这不太重要,即使那样...... 关于javascript-$('.className>butto

javascript - 遍历 children 的 children 并为所有 input 添加函数,同时保持其他 children 不变

我一直在尝试让它工作一段时间,但不确定如何执行以下操作。我的表单组件有包含常规html标记和输入的子组件。如果child是输入,我想添加attachToForm和detachFromForm函数。如果它不是输入,我想继续遍历子项以确保该元素没有子输入字段。无论该元素是否是输入,我仍然希望它出现在我的页面上,我只是想将功能添加到输入。问题是我只能让我的函数只返回输入,删除标签和标题。我知道那是因为我只向newChildren添加带有输入的元素,但是如果我将其他元素推送到elseif部分,我会得到重复项,我可以想到另一种方法来执行此操作。我不确定我是不是不了解基本的JS还是脑子有问题。Re