清除旧的 Meteor 订阅数据
Clear old Meteor subscription data
我有一个使用动态订阅的 Meteor 模板:
var templateId = event.target.value;
Meteor.subscribe('orderTemplateShow', templateId)
templateId
根据我选择的 select 值变化:
<p><label>Select Template</label></p>
<select id="templateSelect" name="templateSelect">
<option disabled selected> Select Template </option>
{{#each orderTemplates}}
<option value="{{this._id}}">{{this.templateName}}</option>
{{/each}}
</select>
一旦我 select 一个模板,模板的信息就会呈现在我在模板上的 table 上。
我的table:
<table id="templateItems" class="table">
<thead>
<tr>
<th>Product Code</th>
<th>Brand</th>
<th>Description</th>
<th>Member Price</th>
<th>Quantity</th>
<th></th>
</tr>
</thead>
<tbody>
{{#each templateItems}}
<tr>
<td>{{productCode}}</td>
<td>{{brand}}</td>
<td>{{description}}</td>
<td>${{memPrice}}</td>
<td><input type="text" id="qty" value ="{{quantity}}"></td>
<td><button class="btn btn-primary removeCartItem">Remove</button></td>
</tr>
{{/each}}
</tbody>
</table>
</form>
但是,当我点击一个新模板时,旧模板中的数据仍然出现在 table 上,此外还有我 select 中的新模板中的数据。因此,有没有办法让我从旧订阅中动态删除数据?
谢谢!
当您订阅该出版物时,保留一个订阅句柄。然后当你想取消订阅时,调用 .stop()
来取消它。
var subHandle = Meteor.subscribe('orderTemplateShow', templateId);
...
subHandle.stop()
我有一个使用动态订阅的 Meteor 模板:
var templateId = event.target.value;
Meteor.subscribe('orderTemplateShow', templateId)
templateId
根据我选择的 select 值变化:
<p><label>Select Template</label></p>
<select id="templateSelect" name="templateSelect">
<option disabled selected> Select Template </option>
{{#each orderTemplates}}
<option value="{{this._id}}">{{this.templateName}}</option>
{{/each}}
</select>
一旦我 select 一个模板,模板的信息就会呈现在我在模板上的 table 上。
我的table:
<table id="templateItems" class="table">
<thead>
<tr>
<th>Product Code</th>
<th>Brand</th>
<th>Description</th>
<th>Member Price</th>
<th>Quantity</th>
<th></th>
</tr>
</thead>
<tbody>
{{#each templateItems}}
<tr>
<td>{{productCode}}</td>
<td>{{brand}}</td>
<td>{{description}}</td>
<td>${{memPrice}}</td>
<td><input type="text" id="qty" value ="{{quantity}}"></td>
<td><button class="btn btn-primary removeCartItem">Remove</button></td>
</tr>
{{/each}}
</tbody>
</table>
</form>
但是,当我点击一个新模板时,旧模板中的数据仍然出现在 table 上,此外还有我 select 中的新模板中的数据。因此,有没有办法让我从旧订阅中动态删除数据?
谢谢!
当您订阅该出版物时,保留一个订阅句柄。然后当你想取消订阅时,调用 .stop()
来取消它。
var subHandle = Meteor.subscribe('orderTemplateShow', templateId);
...
subHandle.stop()