我有一个使用动态订阅的Meteor模板:
var templateId = event.target.value;
Meteor.subscribe('orderTemplateShow', templateId)
templateId
根据我选择的选择值而变化:
<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>
选择模板后,模板的信息将呈现在模板上的表格上。
我的桌子:
<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>
但是,当我单击一个新模板时,除我选择的新模板中的数据外,旧模板中的数据仍会显示在表上。因此,有没有办法让我从旧的订阅中动态删除数据?
谢谢!
订阅发布时,请保留订阅句柄。然后,当您想取消该订阅时,调用.stop()
以取消它。
var subHandle = Meteor.subscribe('orderTemplateShow', templateId);
...
subHandle.stop()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句