Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 理解trasferPropsTo_Javascript_Reactjs - Fatal编程技术网

Javascript 理解trasferPropsTo

Javascript 理解trasferPropsTo,javascript,reactjs,Javascript,Reactjs,我看不出transferPropsTo是用于阅读的 给出的示例如下所示: var Avatar = React.createClass({ render: function() { return this.transferPropsTo( <img src={"/avatars/" + this.props.userId + ".png"} userId={null} /> ); } }); // <Avatar userId={17} w

我看不出
transferPropsTo
是用于阅读的

给出的示例如下所示:

var Avatar = React.createClass({
  render: function() {
    return this.transferPropsTo(
      <img src={"/avatars/" + this.props.userId + ".png"} userId={null} />
    );
  }
});

// <Avatar userId={17} width={200} height={200} />
var Avatar=React.createClass({
render:function(){
将此.transferPropsTo返回(
);
}
});
// 
我看不出这和:

return (
    <img src={"/avatars/" + this.props.userId + ".png"} />
)
返回(
)
还有什么我不明白的:

  • userId={null}
    应该说明什么
  • 被传递一个
    宽度=
    高度=
    。为何他们怎么了

transferPropsTo方法用于将属性从一个对象复制到另一个对象,文档试图准确解释复制的属性

userId={null}
应该说明什么

显式设置不会被
transferPropsTo
覆盖,因此它显示即使
userId
设置在
Avatar
上,也不会被复制,因为
userId
img
上显式设置为null

头像被传递一个宽度=和高度=。为何他们怎么了

这两个属性被“转移”到
img
,因此该示例大致相当于:

return (
    <img src={"/avatars/" + this.props.userId + ".png"} // explicit
         userId={null}                        // explicit, not overwritten
         width={this.props.width}             // copied
         height={this.props.height}           // copied
         />
)
返回(
)

这与原始示例之间的区别在于,构造化身的代码控制在
img
上设置哪些附加属性,而不是
Avatar
的渲染方法本身。

使用
transferPropsTo
方法将属性从一个对象复制到另一个对象,文档试图准确地解释复制了哪些属性

userId={null}
应该说明什么

显式设置不会被
transferPropsTo
覆盖,因此它显示即使
userId
设置在
Avatar
上,也不会被复制,因为
userId
img
上显式设置为null

头像被传递一个宽度=和高度=。为何他们怎么了

这两个属性被“转移”到
img
,因此该示例大致相当于:

return (
    <img src={"/avatars/" + this.props.userId + ".png"} // explicit
         userId={null}                        // explicit, not overwritten
         width={this.props.width}             // copied
         height={this.props.height}           // copied
         />
)
返回(
)

这与原始示例的区别在于,构建化身的代码控制在
img
上设置哪些附加属性,而不是
Avatar
的渲染方法本身。

Awesome,当您从“文档正试图准确解释哪些属性被复制”的角度。非常好,谢谢!太棒了,当你从“文档正试图准确解释哪些属性被复制”的角度来看它时,会更有意义。非常好,谢谢!