Как объединить URL в React Native - PullRequest
0 голосов
/ 25 сентября 2019
"questionnaire": [
        {
            "id": 6,
            "status": "1",
            "name": "Driniking water 24h",
            "lang_id": 2,
            "zona_id": 7,
            "created_at": "2019-05-07 10:35:18",
            "updated_at": "2019-06-01 10:01:08",
            "questionnaire_category": 1,
            "question_number": 1,
            "content": "Driniking water  Driniking water  Driniking water  Driniking water"
        }
    ],
 "next": {
        "id": 7,
        "status": "1",
        "name": "Public Lighting",
        "lang_id": 1,
        "zona_id": 7,
        "created_at": "2019-05-22 05:04:27",
        "updated_at": "2019-06-01 10:00:37",
        "questionnaire_category": 1,
        "question_number": 2,
        "content": "Public Lighting Public Lighting Public Lighting Public Lighting"
    }

Я должен объединить идентификатор анкеты с идентификатором следующего, это мой URL https://quiet -cove-41253.herokuapp.com / api / questionApi / 1 , я не знаюЯ не знаю, как соединить эти два идентификатора. ?????

var response = await fetch(`https://quiet-cove-41253.herokuapp.com/api/questionApi/1/6`+this.state.nextData.id);

state = {
    data: [],
    nextData: []
  };

fetchData = async () => {
    var response = await fetch(`https://quiet-cove-41253.herokuapp.com/api/questionApi/1/6`+this.state.nextData.id);
    var json = await response.json();
    this.setState({ data: json.questionnaire, nextData: json.next });
  };

  componentDidMount() {
    this.fetchData();
  }

render(){
return(
<View><Text>{this.state.data.id}</Text>
                <Text>{this.state.data.name}</Text>
                <Text>{this.state.data.content}</Text>
</View>
)
}

Я хочу сказать, что следующий * * * * * * * * * * * * * * * * * * * * * изменяются

.

1 Ответ

1 голос
/ 25 сентября 2019

Вы можете попробовать с

var response = await fetch(`https://quiet-cove-41253.herokuapp.com/api/questionApi/1/6,${this.state.nextData.id}`);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...