将ID存储在Meteor的反应数组中
我将一个文档ID存储在Meteor的反应词典( https://manual.meteor.com/#deps-creatingreactivevalues )中。
最初,我创build了字典,并将值设置为null
:
Template.templateName.onCreated(function() { this.state = new ReactiveDict; this.state.set('selectedId', null); });
后来我设置了ID
this.state.set('selectedId', id);
现在我需要存储多个ID。 我应该存储的ID为逗号分隔的string值(例如1,5,7,13
)还是有可能以某种方式存储反应数组?
我怎样才能最好地处理这个? 如果我把它作为一个逗号分隔的string存储,我怎样才能添加另一个ID到string或testingID是否在选定的ID之间?
使用reactivearray包https://atmospherejs.com/manuel/reactivearray
添加meteor包
meteor add manuel:reactivearray
例
var arr = new ReactiveArray(['Tom', 'Dick', 'Harry']); Template.templateName.helpers({ names: function() { return arr.list(); } });
推
arr.push('mortensen');
去掉
arr.remove('mortensen');
获得反应模板帮手
arr.list();
清晰的列表
arr.clear();