如果状态为true,我需要从html vue js中的字段拼接该数组
我需要将索引值传递给函数。 怎么可能。
我的错误是
Uncaught ReferenceError: index is not defined
at Object.success (80155f2d-c534-4b8f-ba5f-20edef1496ab:1032)
at i (jquery-3.2.1.min.js:2)
at Object.fireWith [as resolveWith] (jquery-3.2.1.min.js:2)
at A (jquery-3.2.1.min.js:4)
at XMLHttpRequest.<anonymous> (jquery-3.2.1.min.js:4)
我的HTML代码是
<div class="card-content" v-for="(arrest, index) in arestee" :key="index">
--my data--
<a @click="deleteSubmit(arrest)" target="_blank">Delete Arestee</a></button>
</div>
点击deleteSubmit of arrest,我将数据传递给函数
我的vue js代码是
deleteSubmit: function(arrest) {
var vm = this;
data = {};
data['docId'] = this.id;
$.ajax({
url: 'http://localhost:4000/doc/remove/',
data: data,
type: "POST",
dataType: 'json',
success: function(arrest) {
if (arrest.status)
{
alert("Success")
arrest.splice(index, 1);
}
else {
alert("Failed")
}
}
});
return false;
},
arrest.splice(index, 1);
我需要将索引值传递给此
答案 0 :(得分:0)
首先,您必须将index传递给deleteSubmit,因为Vamsi Krishna发表了评论
<a @click="deleteSubmit(arrest, index)" target="_blank">Delete Arestee</a></button>
然后你可以bind回调中的索引:
deleteSubmit: function(arrest, index) {
...
success: function(index, arrest) {
if (arrest.status){
alert("Success")
arrest.splice(index, 1);
} else {
alert("Failed")
}
}.bind(null, index)
...
}