我有以下选择
{{#each orders_db}}
<tr>
<td>{{item}}</td>
<td>
<select class="bootstrapselect orderstatus">
<option data-content="<span class='label label-info'>{{status}}</span>">{{status}}</option>
<option disabled>--------</option>
<option data-content="<span class='label label-primary'>Awaiting</span>">Awaiting</option>
<option data-content="<span class='label label-info'>Taken</span>">Taken</option>
<option data-content="<span class='label label-success'>Delivered</span>">Delivered</option>
<option data-content="<span class='label label-warning'>Shipped</span>">Shipped</option>
<option data-content="<span class='label label-danger'>Cancelled</span>">Cancelled</option>
</select>
</td>
<td>{{client}}</td>
<td>{{location}}</td>
<td>{{responsible}}</td>
</tr>
{{/each}}
JS中的
"change .orderstatus": function(event, template){
console.log($( event.target ).val());
Meteor.call('updateOrder', this._id, $( event.target ).val());
},
orders_db: function(){
return Orders.find({}, {sort: {createdAt: -1}});
}
如何根据状态值更改? 例如。发货应该有标签警告,取消应该有标签危险等等。
答案 0 :(得分:1)
您可以创建一个输入status
的助手并返回标签
//html
<option data-content="<span class='label label-info {{getLabel status}}'>{{status}}</span>">{{status}}</option>
//template js
const labels = {
cancelled: "label-danger",
shipped: "label-warning",
...
}
Template.templateName.helpers({
'getLabel':function(status){
return labels[status];
}
}