admin管理员组文章数量:1023857
{items.filter(item => item.status === 'active').map(item =>
let total_male = item.length + 1;
<p>Male ({total_male})</p>
{this.renderData(item)}
</div>
)}
Is above jsx valid? It make sense to me but it has error. I have a json like this
[{"name":"james","satus":"active"},{"name":"alice","satus":"deactived"}]
I want to count the obj length that has status active.
{items.filter(item => item.status === 'active').map(item =>
let total_male = item.length + 1;
<p>Male ({total_male})</p>
{this.renderData(item)}
</div>
)}
Is above jsx valid? It make sense to me but it has error. I have a json like this
[{"name":"james","satus":"active"},{"name":"alice","satus":"deactived"}]
I want to count the obj length that has status active.
Share Improve this question asked Mar 2, 2017 at 9:26 MellisaMellisa 6053 gold badges12 silver badges22 bronze badges 03 Answers
Reset to default 1Write it like this:
var a = [
{"name":"james","status":"active"},
{"name":"alice","status":"deactived"}
];
class App extends React.Component {
_createList() {
let count=0, active;
active = a.filter(item => item.status === 'active');
count = active.length;
return active.map(item => <div>
<p>Male Count: {count}</p>
{this.renderData(item)}
</div>
)
}
renderData(item){
return <div>{item.name}</div>
}
render() {
return (
<div>
{this._createList()}
</div>
)
}
}
ReactDOM.render(<App />, document.getElementById('container'));
<script src="https://cdnjs.cloudflare./ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare./ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id='container'/>
The jsx you provided is not valid because:
- There is
</div>
but no opening tag<div>
- The arrow function have have syntax error
- The arrow function have no return statement
item
object have nolength
property (from the JSON data you provided). Maybe you intended to useitems.length
instead?
Fix it:
{items.filter(item => item.status === 'active').map(item => {
let total_male = items.length + 1;
return (
<div>
<p>Male ({total_male})</p>
{this.renderData(item)}
</div>
);
})}
Try to
{items.filter(item => item.status === 'active').map(item =>{
let total_male = item.length + 1;
return (
<div>
<p>Male ({total_male})</p>
{this.renderData(item)}
</div>
)}
)}
You forgot return and closed div.
{items.filter(item => item.status === 'active').map(item =>
let total_male = item.length + 1;
<p>Male ({total_male})</p>
{this.renderData(item)}
</div>
)}
Is above jsx valid? It make sense to me but it has error. I have a json like this
[{"name":"james","satus":"active"},{"name":"alice","satus":"deactived"}]
I want to count the obj length that has status active.
{items.filter(item => item.status === 'active').map(item =>
let total_male = item.length + 1;
<p>Male ({total_male})</p>
{this.renderData(item)}
</div>
)}
Is above jsx valid? It make sense to me but it has error. I have a json like this
[{"name":"james","satus":"active"},{"name":"alice","satus":"deactived"}]
I want to count the obj length that has status active.
Share Improve this question asked Mar 2, 2017 at 9:26 MellisaMellisa 6053 gold badges12 silver badges22 bronze badges 03 Answers
Reset to default 1Write it like this:
var a = [
{"name":"james","status":"active"},
{"name":"alice","status":"deactived"}
];
class App extends React.Component {
_createList() {
let count=0, active;
active = a.filter(item => item.status === 'active');
count = active.length;
return active.map(item => <div>
<p>Male Count: {count}</p>
{this.renderData(item)}
</div>
)
}
renderData(item){
return <div>{item.name}</div>
}
render() {
return (
<div>
{this._createList()}
</div>
)
}
}
ReactDOM.render(<App />, document.getElementById('container'));
<script src="https://cdnjs.cloudflare./ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare./ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id='container'/>
The jsx you provided is not valid because:
- There is
</div>
but no opening tag<div>
- The arrow function have have syntax error
- The arrow function have no return statement
item
object have nolength
property (from the JSON data you provided). Maybe you intended to useitems.length
instead?
Fix it:
{items.filter(item => item.status === 'active').map(item => {
let total_male = items.length + 1;
return (
<div>
<p>Male ({total_male})</p>
{this.renderData(item)}
</div>
);
})}
Try to
{items.filter(item => item.status === 'active').map(item =>{
let total_male = item.length + 1;
return (
<div>
<p>Male ({total_male})</p>
{this.renderData(item)}
</div>
)}
)}
You forgot return and closed div.
本文标签: javascriptcount jsx within map loopingStack Overflow
版权声明:本文标题:javascript - count jsx within map looping - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745583999a2157473.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论