0

I am trying to embed country - city json file with PrimeReact. I am having difficulty because of this. I'm pulling the information for the country, but the city shows as [Object, object ].

 <AutoComplete
              placeholder="Search Country"
              dropdown
              value={selectedCountryValue}
              id="dd"
              completeMethod={searchCountry}
              onChange={(e) => setSelectedCountryValue(e.value)}
              suggestions={autoFilteredValue}
              field="name"
              style={{ marginLeft: 10, height: 40, width: 267 }}
            />
 <AutoComplete
              placeholder="Search City"
              dropdown
              value={selectedCountryValue}
              id="dd"
              completeMethod={searchCity(selectedCountryValue)}
              onChange={(e) => setSelectedCountryValue(e.value)}
              suggestions={selectedAutoValueCity}
              field="states"
              style={{ marginLeft: 10, height: 40, width: 267 }}
            />

I used variables. When I select the country, the json other data comes. Console.log also works flawlessly

const searchCity = (event) => {
    setTimeout(() => {
      if (event) {
        console.log("here");
        console.log(event.states.map((obj) => obj.name));
        return event.states.map((obj) => obj.name);
      }
    }, 250);
  };

The Json data sequence is also as shown below.


"data" :[
    {
      "code2": "AF",
      "code3": "AFG",
      "name": "Afghanistan",
      "capital": "Kabul",
      "region": "Asia",
      "subregion": "Southern Asia",
      "states": [
        {
          "code": "BDS",
          "name": "Badakhshān",
          "subdivision": null
        },

alpayergul
  • 33
  • 4
  • 1. you did not clear the timer created before each time you executed searchCity, so your debounce here is invalid, 2. the selectedCountryValue you passed when calling the searchCity method is an object? Because you seem to be using selectedCountryValue as an object in searchCity – AmelloAster May 24 '22 at 13:22
  • Is this your issue: https://github.com/primefaces/primereact/issues/1392 – Melloware May 24 '22 at 14:30

0 Answers0