Hi all,
I whipped up a filter that returns a progressive count up to the number specified. No actual Tiddlers returned, just numbers.
This allows an iterative loop of anything within a list, a set number of times. For instance:
<$list filter="[numberOfItems[5]]">
<$button>Button #<<currentTiddler>>
<$action-dosomething ... />
</$button>
</$list>
would give you 5 buttons [1] [2] [3] [4] [5] with their associated actions.
<$list filter="[numberOfItems[3]]">
<$action-sendmessage $message="tm-new-tiddler" title=<<currentTiddler>>/>
</$list>
would create 3 new Tiddlers, "1", "2", and "3".
There's minimal error checking right now. If you say numberOfItems[0] it will return nothing, rather than 1 result called "0". It counts properly from 1 rather than from 0. That's about it!!
I'd be happy to have someone expand on this. If someone's already done it, I'd love to see - I've missed it.
Code:
exports.numberOfItems = function(source,operator,options) {
var results = [];
//source(function(tiddler,title) {
if (operator.operand != "" && operator.operand !="0") {
var operandCount;
for (operandCount = 0; operandCount < parseInt(operator.operand, 10); operandCount++) {
results.push(String(operandCount+1));
}
}
//});
return results;
};
JSON Tiddler attached.
Cheers,
David.