如何从VueJs

时间:2017-08-22 10:43:50

标签: javascript vue.js vuejs2

我正在VueJs 2.0中构建一个小应用程序,我在其中有两个带有Select2插件的选项:

<div class="form-group"><label class="col-sm-2 control-label">Categories:</label>
    <div class="col-sm-4">
        <v-select multiple :options="selectTable" placeholder="Categories"  v-model="categories"></v-select>
    </div>

</div>
<div class="hr-line-dashed"></div>
<div class="form-group"><label class="col-sm-2 control-label">Sub-Categories:</label>
    <div class="col-sm-4">
        <v-select multiple :options="selectSubtractedTable" placeholder="Subtracted Categories"  v-model="subtractedCategories"></v-select>
    </div>

</div>

现在我有一个计算属性来列出这些元素,例如:

computed: {
    selectTable() {
        if(this.model)
        {
            return this.model.map(a => ({
                value: a.id,
                label: a.name
            }));
        }
    },
    selectSubtractedTable() {
        if(this.subModel)
        {
            return this.subModel.map(a => ({
                value: a.id,
                label: a.name
            }));
        }
    }
},

现在我有一个监视功能,它检查第一个列表并从第二个列表中删除元素:

watch: {
    categories(newValue) {
        this.subModel = this.model
        for(var i = 0; i<newValue.length; i++ )
        {
            const element = this.subModel.find(a => a.id == newValue[i].value)
            console.log(element)
            if(element>0)
                this.subModel.splice(index, 1)
        }
    }
}

我的数据集采用以下格式:

this.model = this.subModel = [
    {
        "id":1,"name":"Jeans","created_at":null,"updated_at":null
    },
    {
        "id":2,"name":"Shirts","created_at":null,"updated_at":null
    },
    {
        "id":3,"name":"Top","created_at":null,"updated_at":null
    },
    {
        "id":4,"name":"Women","created_at":null,"updated_at":null
    },
    {
        "id":5,"name":"Men","created_at":null,"updated_at":null
    },
    {
        "id":6,"name":"Jwellary","created_at":null,"updated_at":null
    }
]

const element = this.subModel.find(a => a.id == newValue[i].value)这始终在监视属性

中显示值0

帮帮我。

0 个答案:

没有答案