React -render values onClick of tabs

kcNeko

I have an app that uses axios and that render the values (eg: ID and warehouseName) using map which i put on tabs. Now I want to do is post a state on warehouseID at loadBrandTotal() from the value ID that I get in the map.

So far my code is like this

export default React.createClass({

    getInitialState(){
        return {
            warehouseName: ""
        }
    },

    componentWillMount(){
        this.loadWarehouse();
        this.loadBrandTotal();
    },


    loadWarehouse(){
        var that = this
        var url = api + 'retrieveWarehouseList';
        axios.post(url,
            {
                warehouseName : 'NONE'
            })
        .then(function (response) {
            console.log(response.data);
            that.setState({
              warehouseList : response.data.retrieveWarehouseListResult
            });
          })
        .catch(function (response) {
          console.log(response);
        });
    },

    loadBrandTotal(){
        var that = this
        var url = api + 'retrieveTotalSalesPerBrand';
        axios.post(url,
            {
                 warehouseID : "None"
            })
        .then(function (response) {
            console.log(response.data);
            that.setState({
              totsalesperbrand : response.data.retrieveTotalSalesPerBrandResult
            });
          })
        .catch(function (response) {
          console.log(response);
        });
    },

    render() {
    var wareName = this.state.warehouseList;
    return (
    	<ul className="tabs tabs-transparent">
	        {wareName.map(function(nameoObjects) {
	          return (
	            <li className="tab">
	                <a href="#test1" value={nameoObjects.ID} key={nameoObjects.ID}>{nameoObjects.warehouseName}</a>
	            </li>
	          )
	        })}
	    </ul>
   	)}

})

Thanks a lot in advance.

Jayce444

I'm not 100% sure what you're wanting to do, but is it that inside the loadBrandTotal() function you want to post data you've gotten in the loadWarehouse() function? And if so, WHEN are you wanting to do this posting, as it's rendered? On a button click?

Here's an example where each list element has a button that sends the ID value the element got in the map fucntion to the loadBrandTotal() function, where it's posted (see code comments for changes):

// Give the id as an argument to loadBrandTotal
loadBrandTotal(id){
        var that = this
        var url = api + 'retrieveTotalSalesPerBrand';
        axios.post(url,
            {
                 // Post the ID
                 warehouseID : id
            })
        .then(function (response) {
            console.log(response.data);
            that.setState({
              totsalesperbrand : response.data.retrieveTotalSalesPerBrandResult
            });
          })
        .catch(function (response) {
          console.log(response);
        });
    },

    render() {
    var wareName = this.state.warehouseList;
    return (
        <ul className="tabs tabs-transparent">
            {wareName.map(function(nameoObjects) {
              return (
                <li className="tab">
                    <a href="#test1" value={nameoObjects.ID} key={nameoObjects.ID}>{nameoObjects.warehouseName}</a>
                    // When clicked, this button sends THIS list object's nameoObject ID to the loadBrandTotal function, where it's posted
                    <button onClick{() => this.loadBrandTotal(nameoObjects.ID)}>Post ID</button>
                </li>
              )
            })}
        </ul>
    )}

So in that example, every list element rendered in the map function includes a button that, when clicked, sends its own nameoObject ID to the loadBrandTotal function, where it's posted and the state is set. Is that the kind of thing you're trying to do?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

React onClick function fires on render

From Dev

React Js onClick inside render

From Dev

Render new element onClick in react.js

From Java

Why is my onClick being called on render? - React.js

From Dev

onClick doesn't render new react component.

From Dev

Is there a way to conditionally render content using onClick in react JS?

From Dev

All React-bootstrap Tabs render function gets called every time regardless of which tab was selected

From Dev

Appropriate way to setState in React with values calculated from Redux after render

From Dev

AngularJs Render div onclick

From Dev

AngularJs Render div onclick

From Dev

Render a timer component onClick

From Dev

React.js onClick event returning all null values

From Dev

React: component only rendering new values on second onClick of button

From Dev

React, Adding onClick event directly to Components instead of render element inside said component.

From Dev

Why does adding an onClick method cause an infinite loop in my react render method

From Dev

Anchoring Tabs with React Router

From Dev

Render Multiple PartialView by clicking on relevent tabs

From Dev

Render Multiple PartialView by clicking on relevent tabs

From Dev

rails render view onclick with javascript

From Dev

render a circle onclick event in highcharts

From Dev

rails render view onclick with javascript

From Dev

Jquery tabs - use onclick function to get a content

From Dev

ViewPager within a DialogFragment does not change tabs onClick

From Dev

Passing values from activity to tabs

From Dev

When React functional component re-render, does it reassign assigned values & functions?

From Dev

Can't get values from Array object to render React component [solved]

From Dev

Antdesign tabs react router navigation

From Dev

Python to get onclick values

From Dev

passing values from onClick

Related Related

  1. 1

    React onClick function fires on render

  2. 2

    React Js onClick inside render

  3. 3

    Render new element onClick in react.js

  4. 4

    Why is my onClick being called on render? - React.js

  5. 5

    onClick doesn't render new react component.

  6. 6

    Is there a way to conditionally render content using onClick in react JS?

  7. 7

    All React-bootstrap Tabs render function gets called every time regardless of which tab was selected

  8. 8

    Appropriate way to setState in React with values calculated from Redux after render

  9. 9

    AngularJs Render div onclick

  10. 10

    AngularJs Render div onclick

  11. 11

    Render a timer component onClick

  12. 12

    React.js onClick event returning all null values

  13. 13

    React: component only rendering new values on second onClick of button

  14. 14

    React, Adding onClick event directly to Components instead of render element inside said component.

  15. 15

    Why does adding an onClick method cause an infinite loop in my react render method

  16. 16

    Anchoring Tabs with React Router

  17. 17

    Render Multiple PartialView by clicking on relevent tabs

  18. 18

    Render Multiple PartialView by clicking on relevent tabs

  19. 19

    rails render view onclick with javascript

  20. 20

    render a circle onclick event in highcharts

  21. 21

    rails render view onclick with javascript

  22. 22

    Jquery tabs - use onclick function to get a content

  23. 23

    ViewPager within a DialogFragment does not change tabs onClick

  24. 24

    Passing values from activity to tabs

  25. 25

    When React functional component re-render, does it reassign assigned values & functions?

  26. 26

    Can't get values from Array object to render React component [solved]

  27. 27

    Antdesign tabs react router navigation

  28. 28

    Python to get onclick values

  29. 29

    passing values from onClick

HotTag

Archive