簡體   English   中英

從vue.js中的對象通過數組訪問v-repeat中的屬性

[英]access properties in v-repeat over array from objects in vue.js

我有一個5個類別的json結果,我想用v-repeat遍歷。 我使用推方法將結果傳遞給我的vue模型。

該設置是我的記錄所屬的5個不同類別。 每個類別必須顯示在不同的選項卡中(我刪除了與結果無關的類別過濾器,原因與該問題無關)。

記錄顯示得很完美(v-repeat =“ results”),我也得到了5個制表符,但沒有值(文本也沒有值)。

console.log(this.categories)給了我一個由5個對象組成的數組,這些對象無法成功顯示其屬性...我在做什么錯?

我嘗試了各種事情,例如$ value,categorie:categories,...

我對我的類別的API調用產生的JSON結果:

{
    status: "success",
    data: {
        results: {
            general: "Algemeen",
            metadata: "Meta-data",
            facebook: "Facebook",
            twitter: "Twitter",
            googleplus: "Google+"
        }
    }
}

在我的Vue文件中獲取:

fetchCategories: function(){
    this.$http.get('/api/tokens/categories', function (response) {

        for(var prop in response.data.results) {
            this.categories.push({text: response.data.results[prop], value: prop});
        }
    });
},

我的看法是:

<tabs>
    <tab v-repeat="category in categories" header="@{{ category.text }}">
        <div id="@{{ category.value }}">
            <table id="@{{ category.value }}-token-list" class="data-list">
                <tr>
                    <th>id</th>
                    <th>categorie</th>
                    <th>naam</th>
                    <th>slug</th>
                </tr>
                <tr v-repeat="results" v-class="odd: (index%2!=0)">
                    <td>@{{ id }}</td>
                    <td>@{{ category }} </td>
                    <td>@{{ name }} </td>
                    <td>@{{ slug }}</td>
                </tr>
            </table>
        </div>
    </tab>
</tabs>

編輯:

我寫這篇文章的時候確實得到了我的價值:

@{{ categories[0].text }} or @{{ categories[0].value}}

編輯2:

VueStrap的制表符功能存在問題。 當我只使用帶有@ {{value}}的列表時,一切都很好

似乎是0.12問題。 升級到1.0.x將是解決方案!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM