【发布时间】:2019-09-19 00:19:18
【问题描述】:
在我的 Vuejs 组件中,我正在动态填充数据表
即在我的methods:
displayUserTypes(){
axios.get('/antenna-monitor/pull-user-types').then( ({data}) =>
{
for(var i in data)
{
$('#user-roles').dataTable().fnAddData( [
data[i].name,
data[i].description,
'<a href="#" title="Edit" @click.prevent="editModal"><i class="fa fa-edit"></i></a> | <a href="#" title="Delete"><i class="fa fa-trash"></i></a>'
]);
}
},
created() {
this.displayUserTypes();
}
这是组件的 HTML 部分:
<button class="btn btn-success" @click="addModal"><i class="fa fa-plus"></i>Add New</button>
<table id="user-roles" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Action</th>
</tr>
</thead>
</table>
请注意,在我的displayUserTypes 函数中,当填充数据表时,我会附加一个编辑锚标记并在其中传递editModal 方法。单击此编辑链接应触发一个模式,如下所示:
在我的方法中:
addModal(){
$('#userRolesModal').modal('show');
},
editModal(){
$('#userRolesModal').modal('show');
},
但是editModal 函数没有触发模态。我已经确认模态运行良好,因为我添加调用addModal 函数的按钮会触发模态。所以我的想法是,因为我从动态创建的链接中调用了editModal 函数,所以我可能需要将一些额外的东西传递给我的代码来触发这个方法?
【问题讨论】:
-
你好,是组件中的方法,还是父vue中的方法?
-
嗨@LoïcMonard。它们在组件中
标签: javascript datatables vuejs2 vue-component