【发布时间】:2016-09-13 16:29:52
【问题描述】:
所以我有一个表,其中的行是使用 v-for 动态创建的:
<table>
<tr><th class='name'>Name</th><th>Surname</th></tr>
<tr v-for='data in datas'><td class='name'>@{{data.name}}</td><td>@{{data.surname}}</td></tr>
</table>
然后,使用 jQuery,我想隐藏具有类“名称”的列,但是当我制作时
$('.name').hide();
只有标题消失。我想这是因为该行是动态生成的,但是我该如何处理呢?
我试过了:
- 使用该类对所有元素创建 each() 函数,
- 编写像
.css('display','none')这样的脚本,而不是hide()
但这没有帮助。奇怪,但 each() 中的 alert() 每次应该触发时都会触发,但 hide() 会忽略添加的元素
更具体的数据: 表本身:
<table class="striped bordered responsive">
<thead>
<tr><th class="stat-table-creatives" colspan="2">Creative info</th><th>Impressions</th><th>Clicks</th><th>CTR</th><th>CPC</th><th>Price per unit</th><th>Sum</th><th class="stat-table-date">Date</th></tr>
</thead>
<tbody>
<tr v-for="stat in stats"><td class="stat-table-creatives">@{{ stat.creativeTitle }}</td><td class="stat-table-creatives">@{{ stat.creativeType }}</td><td>@{{ stat.impressions }}</td><td>@{{ stat.clicks }}</td><td>@{{ stat.ctr }}</td><td>@{{ stat.cpc }}</td><td>@{{ stat.client_price }}</td><td>@{{ stat.sum }}</td><td class="stat-table-date">@{{ stat.date }}</td></tr>
</tbody>
</table>
点击按钮调用函数
getJsonForStats: function(filters){
if((filters[0]=='creative')||(filters[1]=='creative')){
$('.stat-table-creatives').show();
} else {
$('.stat-table-creatives').hide();
}
if((filters[0]=='date')||(filters[1]=='date')){
$('.stat-table-date').show();
} else {
$('.stat-table-date').hide();
}
});
该函数是从另一个函数调用的,该函数在 v-on:click 上调用
【问题讨论】:
-
你为什么不像
.name { display: none; }987654330@这样添加一个CSS定义 -
@aifrim 我需要在文档加载时显示此列,并在单击按钮时隐藏它
-
好的,那么这个
$("#hide-button").click(function() { $(".name").hide(); });应用在domready应该可以工作:) -
你试过
$("#TableID .name").hide(); -
@aifrim 但它没有
标签: javascript jquery html css vue.js