Невозможно передать информацию о методе выборки в данные экземпляра - PullRequest
1 голос
/ 12 марта 2019

Когда я запускаю приведенный ниже код, значения внутри переменной currencie не отображаются.

Я не могу передать информацию о методе выборки в данные экземпляра.Я хотел бы получить данные и отобразить их на экране.Если я использую console.log, я могу видеть данные, как и ожидалось.

 <template>
        <Page class="page">
            <ActionBar title="Tela N°1" class="action-bar" />
            <ScrollView>
                <StackLayout class="home-panel">
                    <!--Add your page content here-->
                    <Label textWrap="true" text="Primeira tela criada usando NativeScript"
                        class="h2 description-label" />
                    <Button text="Segunda Tela" @tap="onButtonTap" />
                    <Button text="Terceira Tela" @tap="onButton" />
                    <ListView class="list-group" for="currencie in currenciess"
                        style="height:1250px">
                        <v-template>
                            <FlexboxLayout flexDirection="row" class="list-group-item">
                                <Label :text="currencie.name" class="list-group-item-heading" style="width: 60%" />
                                <Label :text="currencie.buy" class="list-group-item-heading"
                                    style="width: 60%" />
                            </FlexboxLayout>
                        </v-template>
                    </ListView>
    </StackLayout>
            </ScrollView>
        </Page>
    </template>

    <script>
        import Second from "./Second";
        import Third from "./Third";
        const http = require("tns-core-modules/http");
        const url = "https://api.hgbrasil.com/finance?key=c5239f9c";
        export default {
            data() {
                return {
                    currenciess: []
                };
            },                    
    mounted() {
                fetch(url)
                    .then(response => response.json())
                    .then(results => {
                        this.currenciess = results.results.currencies.USD;
                    });
            },
        };
    </script>

1 Ответ

0 голосов
/ 12 марта 2019

Измените ваш смонтированный метод.currenciess - это массив, в то время как ваш results.results.currencies["USD"] - это объект, поступающий из API.Я создал игровую площадку для вас здесь .

mounted() {
            console.log("mounted");
            fetch(url)
                .then(response => response.json())
                .then(results => {
                    this.currenciess.push(results.results.currencies["USD"]);
                });
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...