我面临一个无限循环问题,我无法看到触发它的是什么.它似乎在渲染组件时发生.
我有三个组件,组织如下:
TimelineComponent
|--PostComponent
|--UserPopover
Run Code Online (Sandbox Code Playgroud)
TimelineComponenet:
React.createClass({
mixins: [
Reflux.listenTo(TimelineStore, 'onChange'),
],
getInitialState: function() {
return {
posts: [],
}
},
componentWillMount: function(){
Actions.getPostsTimeline();
},
render: function(){
return (
<div className="timeline">
{this.renderPosts()}
</div>
);
},
renderPosts: function (){
return this.state.posts.map(function(post){
return (
<PostComponenet key={post.id} post={post} />
);
});
},
onChange: function(event, posts) {
this.setState({posts: posts});
}
});
Run Code Online (Sandbox Code Playgroud)
PostComponent:
React.createClass({
...
render: function() {
return (
...
<UserPopover userId= {this.props.post.user_id}/>
...
);
}
});
Run Code Online (Sandbox Code Playgroud)
UserPopover:
module.exports = React.createClass({ …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用lodash.js删除重复的项目,但我无法使其正常工作.
这是数组中对象的结构:
{
label: 'tagA',
value: 1
}
Run Code Online (Sandbox Code Playgroud)
那么就说我有这个数组:
var objectsArray = [
{
label: 'tagA',
value: 1
},
{
label: 'tagB',
value: 2
},
{
label: 'tagC',
value: 3
},
{
label: 'tagB',
value: 4
},
{
label: 'tagB',
value: 5
},
];
Run Code Online (Sandbox Code Playgroud)
我提出这段代码与_.uniqBy()从lodash.js功能尝试用相同的标记除去数组的元素,但它不到风度工作,因为我预期:
var uniq = _.uniqBy(objectsArray, function(o){
return o.label;
});
Run Code Online (Sandbox Code Playgroud)
我基于在这里和那里找到的一些样本和当然的lodash文档,但我在这方面缺乏知识所以任何帮助它将超级欣赏它.
谢谢.