1
我正在Meteor写一个小应用程序。我完成了添加类别的代码,但我不知道如何删除类别。 我的HTML代码是:删除Meteor.js中的类别
<template name="categories">
<h2>Stored Category</h2>
<div id="categories" class="btn-group">
{{#if new_cat}}
<div id="category">
<input type="text" id="add-category" value=""/>
</div>
{{else}}
<div class="category btn btn-inverse" id="btnNewCat">+</div>
{{/if}}
{{#if del_cat}}
<div id="category">
<input type="text" id="del-category" value=""/>
</div>
{{else}}
<div class="category btn btn-inverse" id="btnDelCat">−</div>
{{/if}}
{{#each lists}}
<div class="category btn btn-inverse">
{{Category}}
</div>
{{/each}}
</div>
增加一个类别中的按钮,很明显,btnNewCat和删除是btnDelCat。 Javascript代码是:
Template.categories.lists = function() {
return lists.find({}, {sort: {Category: 1}});
};
Session.set('adding_category', false);
Session.set('deleting_category', false);
Template.categories.new_cat = function() {
return Session.equals('adding_category',true);
};
Template.categories.del_cat = function(){
return Session.equals('deleting_category',true);
};
Template.categories.events({
'click #btnNewCat': function (e, t) {
Session.set('adding_category', true);
Meteor.flush();
focusText(t.find("#add-category"));
},
'keyup #add-category': function (e,t){
if (e.which === 13)
{
var catVal = String(e.target.value || "");
if (catVal)
{
lists.insert({Category:catVal});
Session.set('adding_category', false);
}
}
},
'focusout #add-category': function(e,t){
Session.set('adding_category',false);
},
'click #btnDelCat': function (e, t) {
Session.set('deleting_category', true);
Meteor.flush();
focusText(t.find("#del-category"));
},
'keyup #del-category': function (e,t){
if (e.which === 13)
{
var catVal = String(e.target.value || "");
if (catVal)
{
alert(catVal);
lists.remove({Category:catVal});
Session.set('deleting_category', false);
}
}
},
'focusout #del-category': function(e,t){
Session.set('deleting_category',false);
}
我尝试使用 lists.remove({范畴:catVal})以去除;。这是行不通的。我哪里错了?
谢谢
eb_cj
@richsilva - 它工作正常。谢谢 –