1
我想让流星清除最后一个查询,它不积累我的研究成果。如果我在输入“NºPatrimónio”中搜索,然后在“CódigoInformática”中再次搜索,我想清除第一个查询结果。发生的事情是它汇集了第一个和第二个查询结果。总结一下,我想单独查询结果。 Meteor search page流星搜索清除结果
模板
<tbody>
<tr>
<th>Nº Património</th>
<th>Equipamento</th>
<th>Utilizador</th>
<th>Nº Helpdesk</th>
<th>Data Aquisição</th>
<th>Data Saída</th>
<th>Ultima Alteração</th>
</tr>
{{#each pesquisaEquipamentos}}
<tr>
<td>
{{npatrimonio}}
</td>
<td>
{{equipamento}}
</td>
<td>
{{utilizadores}}
</td>
<td>
{{helpdesk}}
</td>
<td>
{{daquisicao}}
</td>
<td>
{{dsaida}}
</td>
<td>
{{createdAt}}
</td>
</tr>
{{/each}}
</tbody>
助手
if (Meteor.isClient) {
Template.pesquisar.helpers({
pesquisaEquipamentos: function() {
return Equipamentos.find();
}
});
Template.pesquisar.events({
"keypress input": function(event, template) {
if (event.keyCode == 13) {
var search = {};
search.value = event.target.value
search.name = event.target.name
//console.log(search.name, search.value);
Meteor.subscribe("pesquisaEquipamentos", search);
event.target.value = '';
}
}
});
}
公开
Meteor.publish("pesquisaEquipamentos", function(search) {
//console.log(search.name);
//console.log(search.value);
switch (search.name) {
case 'npatrimonio':
return Equipamentos.find({
npatrimonio: search.value
});
break;
case 'cinformatica':
return Equipamentos.find({
cinformatica: search.value
});
break;
default:
}
});
谢谢,它有效;) –