有没有办法将一个组件传递到另一个反应组件?我想创建一个模型反应组件并传入另一个反应组件以转换该内容.
编辑:这是一个reactJS codepen,说明我正在尝试做什么.http://codepen.io/aallbrig/pen/bEhjo
HTML
<div id="my-component">
<p>Hi!</p>
</div>
Run Code Online (Sandbox Code Playgroud)
ReactJS
/**@jsx React.DOM*/
var BasicTransclusion = React.createClass({
render: function() {
// Below 'Added title' should be the child content of <p>Hi!</p>
return (
<div>
<p> Added title </p>
{this.props.children}
</div>
)
}
});
React.renderComponent(BasicTransclusion(), document.getElementById('my-component'));
Run Code Online (Sandbox Code Playgroud) 总是为函数返回值("undefined")的值是什么,不需要显式返回任何内容?
为什么这是一个规则,它捕获了什么错误?
你可以在这里阅读有关ESLint的"一致回报"规则(回答"什么",而不是"为什么").
您可以阅读一个推测性的分析,为什么javascript函数在堆栈溢出时隐式返回undefined.
我有指令myDirective,它有一个双向绑定隔离范围.当用户单击按钮时,我想将隔离范围更改为值.我认为隔离范围与$ scope绑定,但我错了.我如何"抓住"并与该隔离范围进行交互?它们是否与指令控制器的范围无关?
angular.module("app", [])
.controller("myCtrl", function($scope){
$scope.ctrlTwoway = "Eggs";
})
.directive("myDirective", function(){
return {
scope: {
twoway: =
},
template: "<button ng-click="changeTwoway()">Change two way isolate scope</button>",
controller: function($scope, $element, $attrs){
$scope.changeTwoway = function(){
// get twoway from isolate scope, and update the value with "bacon"
// $scope.twoway = "bacon" doesn't work
// nor does $attrs.twoway = "bacon" work, either :(
};
}
}
});
Run Code Online (Sandbox Code Playgroud)
和HTML
...
<div my-directive twoway="{{ctrlTwoway}}"></div>
Current value: {{ctrlTwoway}}
Run Code Online (Sandbox Code Playgroud)