Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从返回的数据组件vuejs拼接子阵列?_Javascript_Arrays_Vuejs2_Array Splice - Fatal编程技术网

Javascript 如何从返回的数据组件vuejs拼接子阵列?

Javascript 如何从返回的数据组件vuejs拼接子阵列?,javascript,arrays,vuejs2,array-splice,Javascript,Arrays,Vuejs2,Array Splice,我有一个对象是数组列表 ..这是在vue js中从道具声明的数据: data: function(){ return{ listaSelezionati:this.selezionati } } …在v-for上渲染 <div class="row" style="margin-bottom:20px;" v-for="(selezionato,index) in listaSelezionati"> 但它什么也没用,有人有什么建议吗 e

我有一个对象是数组列表

..这是在vue js中从道具声明的数据:

    data: function(){
    return{
        listaSelezionati:this.selezionati
    }
}
…在v-for上渲染

<div class="row" style="margin-bottom:20px;" v-for="(selezionato,index) in listaSelezionati">
但它什么也没用,有人有什么建议吗

edit1
我想知道
return{this.listaSelezionati
是否应该是编辑组件数据的正确方法

看起来您的数组太深了

this.listaSelezionati[index]
是一个数组,但是

this.listaSelezionati[index][0]
看起来像数组的第一个元素,它是一个对象。所以现在看起来像是在位置索引处拼接对象。这应该会产生错误。 我认为你需要:

rimuovi : function(outterIndex, innerIndex){
    alert(outterIndex, innerIndex);
    return{
        this.listaSelezionati[outterIndex].splice(innerIndex,1)
    }
}

<div class="remove pull-right" v-on:click="rimuovi(index, innerIndex)"></div>
// or
<div class="remove pull-right" v-on:click="rimuovi(outterIndex, innerIndex)"></div>
rimuovi:函数(outterIndex,innerIndex){
警报(outterIndex、innerIndex);
返回{
this.listaSelezionati[outterIndex].splice(innerIndex,1)
}
}
//或

我还没有测试过它,但至少它应该可以让您更接近

如果您想按索引删除整个子数组,那么您需要做的就是:

methods:{
  rimuovi : function(index){
    this.listaSelezionati.splice(index,1)
  }
}

无需返回值;更新所调用的数组。

this.listaSelezionati[index][0]将指向子数组对象。您正在对象上放置拼接函数。是否要删除特定索引处的子数组?是否有另一个
v-for
位置?@BertEvans no是唯一的一个,但在v-for之前有一个v-if,您要删除一个子数组?@BertEvans是的,但也知道if
返回{this.listaSelezionati
是修改组件da objecthmm的正确方法……有趣的是,我应该使用索引调用outterIndex和innerIndex吗?
rimuovi : function(outterIndex, innerIndex){
    alert(outterIndex, innerIndex);
    return{
        this.listaSelezionati[outterIndex].splice(innerIndex,1)
    }
}

<div class="remove pull-right" v-on:click="rimuovi(index, innerIndex)"></div>
// or
<div class="remove pull-right" v-on:click="rimuovi(outterIndex, innerIndex)"></div>
methods:{
  rimuovi : function(index){
    this.listaSelezionati.splice(index,1)
  }
}