JavaScript Count checked checkboxes in React.js count checked checkboxes jquery,count checked checkboxes google sheets,count

I'm using a document structure like this

render() {
return (
    <div className="MyComponent">
        <ul className="">
            {parseRecommendations(this.props.recommendations)}
        </ul>
    </div>
);
}

function parseRecomendations(recommendations) {
    return recommendations.map((recommendation, key) => {
        return (<Recommendation data={recommendation} key={key} />);
    });
}

Where each Recommendation is its own component containing a checkbox

class Recommendation extends Component {
    const recommendation = this.props.data;
    const pageUrl = recommendation.url;

    return (
        <li className="article-item" key={key}>
            <div className="article-info">
                <input type="checkbox" defaultChecked="checked" aria-described-by={recommendation.pii} />
                <a className="journal-title" target='_blank' href={pageUrl} id={recommendation.pii}>{recommendation.title}</a>
            </div>
        </li>
    );

I'd like to have a title saying [Download (x) PDFs], where x is the number of selected checkboxes. How do I find the value of x in this case?

Answer:1

You need to store information about whether input is "checked" in your data. Then, simply count items with truthy "checked" flag.

Here is my solution. You should be able to get principle here and modify your code.

const data = [
    { checked: false, value: 'document 1' },
    { checked: true, value: 'document 2' },
    { checked: true, value: 'document 3' },
    { checked: false, value: 'document 4' },
    { checked: false, value: 'document 5' },
];

const Item = props => (
    <div>
        <input type="checkbox" checked={props.checked} onChange={props.onCheckChange} />
        { props.value }
    </div>
)
var Hello = React.createClass({
    getInitialState() {
        return {
            items: this.props.items.concat(),
        };
    },

    onCheckChange(idx) {
        return () => {
            const items = this.state.items.concat();
            items[idx].checked = !items[idx].checked;
            this.setState({items});
        }
    },

    totalChecked() {
        return this.state.items.filter(props => props.checked).length;
    },

  render() {
    return (
            <div>
                { this.state.items.map((props, idx) => (
                    <Item {...props} key={idx} onCheckChange={this.onCheckChange(idx)} />
                )) }
                Total checked: { this.totalChecked() }
            </div>
        );
  }
});

ReactDOM.render(
  <Hello items={data} />,
  document.getElementById('container')
);
Answer:2

My Ajax function $.ajax({ type: "POST", contentType: 'application/json;charset=utf-8', dataType:'json', url: 'getSites', data: JSON.stringify(), ...

My Ajax function $.ajax({ type: "POST", contentType: 'application/json;charset=utf-8', dataType:'json', url: 'getSites', data: JSON.stringify(), ...

  1. when is data reliable
  2. when census data released
  3. when is data relevant
  4. when is data relational

I have little leaflet application where the app get geoJson objects from server, and display it, specially LineString. The json parser that i use on server side works properly. And the client side ...

I have little leaflet application where the app get geoJson objects from server, and display it, specially LineString. The json parser that i use on server side works properly. And the client side ...

  1. leaflet swap coordinates

This is my code,i don't know why case 0, and case 1 are not working? are there any responses for these levels? This is the output request received processing request request finished and response is ...

This is my code,i don't know why case 0, and case 1 are not working? are there any responses for these levels? This is the output request received processing request request finished and response is ...

How can i draw only two images with reversing I don't know how to reverse. Pls help. var canvas = document.createElement('canvas'); canvas.width = 16 * scale; canvas.height = 32 * scale; ...

How can i draw only two images with reversing I don't know how to reverse. Pls help. var canvas = document.createElement('canvas'); canvas.width = 16 * scale; canvas.height = 32 * scale; ...

  1. horizontally flip image iphone
  2. horizontally flip image css
  3. horizontally flip image python
  4. horizontally flip image online
  5. vertical flip image
  6. vertical flip image python
  7. vertical flip image iphone
  8. vertical flip image online
  9. vertical flip image css
  10. vertical flip image matlab
  11. flip image horizontally photoshop
  12. flip image horizontally android
  13. flip image horizontally after effects
  14. flip image horizontally matlab
  15. flip image horizontally premiere
  16. flip image horizontally illustrator
  17. flip image horizontally html
  18. flip image horizontally powerpoint
  19. flip image horizontally java
  20. flip image horizontally opencv