javascript - dataTables 新行不会添加到表中
问题描述
当我添加新数据时,它不会添加到表中
代码
HTML
<thead>
<tr>
<th class="text-center">ID</th>
<th class="text-center">Number</th>
<th class="text-center">Body</th>
<th class="text-center">Heading</th>
<th class="text-center">Book</th>
<th class="text-center">Chapter</th>
<th class="text-center">Actions</th>
</tr>
</thead>
<tbody>
<template v-for="verse in getVerses">
<tr v-bind:key="verse.id">
<td width="30" class="text-center">{{ verse.id }}</td>
<td class="text-center">{{ verse.number }}</td>
<td>{{ verse.body }}</td>
<td>{{ verse.heading }}</td>
<td class="text-center">{{ verse.book.name }}</td>
<td class="text-center">{{ verse.chapter.name }}</td>
<td class="text-center">
<button class="btn btn-sm btn-danger" type="button" @click="deleteVerse(verse.id)">Delete</button>
</td>
</tr>
</template>
</tbody>
</table>
Script
export default {
name: "adminVerses",
data() {
return {
isLoading: true,
type: '',
books: [],
errors: [],
pageTitle: 'Manage Verses',
getChapters: [],
getVerses: [],
isLoadingChapters: true,
isLoadingVerses: true,
verse: {
number: 1,
heading: '',
body: '',
book_id: '',
chapter_id: '',
}
}
},
methods: {
submit: function(e) {
axios.post('/api/saveVerse', this.verse)
.then(res => {
this.isLoading = false;
$('#exampleModal').modal('toggle');
this.getVerses.push( res.data.verse );
this.verse = {
number: parseInt(this.verse.number) + 1,
heading: '',
body: '',
book_id: this.verse.book_id,
chapter_id: this.verse.chapter_id,
};
})
.catch(error => {
// handle authentication and validation errors here
this.errors = error.response.data.errors
this.isLoading = false
})
},
}
}
任何想法?
更新
通过添加
if ($.fn.dataTable.isDataTable('#verses')) {
$('#verses').DataTable().clear().destroy(); //This will destroy datatable
};
this.getVerses.push( res.data.verse );
现在我可以将新添加的数据放入我的表中,但我也将失去分页和搜索等功能。
想法?
解决方案
打开您的 vue devtools 并检查 getVerses 是否获得正确的数据
推荐阅读
- php - 用于复选框和 jquery 的 php 会话或 cookie 删除
- javascript - 如何使用 Adonis 中的用户角色更新联结表
- wordpress - 删除手持页脚菜单链接 Woocommerce
- excel - Excel 插件:如何检测/防止 Excel 用户删除工作表?
- django - django-cities:找不到 GDAL 库
- python - 无法使用“os.environ”检索数组环境变量
- java - 在不支持 PagedResultsControl 的 LDAP 服务器上分页
- qt - Qt QSslSocket comodo 正 ssl
- excel - Excel:在一个单元格中查找多个值并在另一个单元格中返回结果
- python - 使用棉花糖序列化 sqlalchemy hybrid_property