Данные не отображаются в HTML - PullRequest
0 голосов
/ 04 июля 2019

У меня проблема с отображением данных из моей переменной itemListPrice.Я проверил в консоли, и данные заполняются в itemListPrice, но его нет в моем html, я все загружаю неправильно?

Вот разметка

<div id="app2">
    <div id="TableContainer" style="width:798px !important">
        <div class="table-responsive">
            <table class="table">
                <thead>
                    <tr>
                        <td><label>Catalog Name</label></td>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>{{ currentCatalogName }}</td>
                    </tr>
                </tbody>
            </table>

            <table class="table">
                <thead>
                    <tr>
                        <td><label>Item Name</label></td>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td> {{ itemPriceList.Name }}</td>
                    </tr>
                </tbody>
            </table>

            <table class="table">
                <thead>
                    <tr>
                        <td colspan="2"><label>Item List</label></td>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td width="575px">${{ itemPriceList.ItemListPrice }}</td>
                        <td>${{ itemPriceList.ItemListPrice }}</td>
                    </tr>
                </tbody>
            </table>

            <table class="table">
                <thead>
                    <tr>
                        <td colspan="3"><label>Item Features</label></td>
                        <td></td>
                    </tr>
                </thead>
                <tbody>
                    <template v-for="item in itemPriceList.ItemFeatures">
                        <tr v-if="item.FeatureQuantity != 0">
                            <td width="250px">{{ item.FeatureName }}</td>
                            <td>{{ item.FeatureQuantity }}</td>
                        </tr>
                    </template>
                </tbody>
            </table>

            <table class="table">
                <thead>
                    <tr>
                        <td><label>Item IAM</label></td>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>{{ itemPriceList.ItemIAM }}</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

и вот мой код

new Vue({
    el: '#app2',
    beforeCreate: function () {
        StartBusyIndicator("#ItemPriceListWindow");
    },
    created: function () {
        this.GetItemDetails();
    },
    mounted: function () {
        StopBusyIndicator("#ItemPriceListWindow");
    },
    data: {
        itemPriceList: [],
        orderItems: currentOrderItems,
        currentCatalogName: currentCatalog,
        priceList: null
    },
    methods: {
        GetItemDetails: function () {
            TryCatch(function() {
                let result = GetItemPriceDetails();
                this.itemPriceList = result;
                priceList = result;
            });
        },
        GetOrderItems: function () {

        },
        OptionPriceSplitter: function (optionprice) {
            return TryCatch(function() {
                let sentenceSplit = optionprice.split('& ');
                let comp = '';

                for (let i = 0; i < sentenceSplit.length; i++) {
                    comp += sentenceSplit[i] + '\n';
                }
                return sentenceSplit;
            });
        },
        GlobalListPriceCalculation: function (globalgroupid) {
            return TryCatch(function() {
                let listPrice = 0.00;
                let priceList = this.itemPriceList;
                let result = priceList.GlobalListPrices.filter(function(item) {
                    if (item.GlobalGroupID == globalgroupid) {
                        listPrice = listPrice + item.Price;
                    }
                });

                if (listPrice == 0) {
                    listPrice = "";
                } else {
                    listPrice = "$" + listPrice.toFixed(2);
                }
                return listPrice;
            });
        }
    }
});

1 Ответ

0 голосов
/ 04 июля 2019

при условии, что TryCatch(cb) является чем-то вроде

function TryCatch(cb){ let x = null; try { x = cb() } catch(e) {} return x; }

вас потерянных 2 важных вещей:

  • this (вы можете связатьэто через cb.call(this))
  • совершенно полезные сообщения об ошибках

дальнейшие пункты:

Я проверил в консоли

Оформить отличный плагин для браузера для ff и chrome vue-devtools

itemPriceList = []

вы инициализируете itemPriceListкак массив, используйте его как массив item in itemPriceList, но также используйте его как объект {{ itemPriceList.Name }} - что это будет?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...