kopia lustrzana https://github.com/miklobit/TiddlyWiki5
added list suffix for each filter
implements #1369 when the suffix is `list`, interprets the field as a list of individual tiddler titles and returns all titles referenced in the list field of the source list, existing or notprint-window-tiddler
rodzic
8a763e9d83
commit
baca2703f1
|
@ -3,7 +3,8 @@ title: $:/core/modules/filters/each.js
|
|||
type: application/javascript
|
||||
module-type: filteroperator
|
||||
|
||||
Filter operator that selects one tiddler for each unique value of the specified field
|
||||
Filter operator that selects one tiddler for each unique value of the specified field.
|
||||
With suffix "list", selects all tiddlers that are values in a specified list field.
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
@ -17,19 +18,23 @@ Export our filter function
|
|||
*/
|
||||
exports.each = function(source,operator,options) {
|
||||
var results = [],
|
||||
values = {};
|
||||
values = {},
|
||||
list = "list" === operator.suffix;
|
||||
source(function(tiddler,title) {
|
||||
if(tiddler) {
|
||||
var value;
|
||||
if((operator.operand === "") || (operator.operand === "title")) {
|
||||
value = title;
|
||||
} else {
|
||||
value = tiddler.getFieldString(operator.operand);
|
||||
}
|
||||
if(!$tw.utils.hop(values,value)) {
|
||||
values[value] = true;
|
||||
results.push(title);
|
||||
}
|
||||
var value,
|
||||
field = operator.operand || "title";
|
||||
$tw.utils.each(
|
||||
list ?
|
||||
options.wiki.getTiddlerList(title,field) :
|
||||
[ "title" === field ? title : tiddler.getFieldString(operator.operand)],
|
||||
function(value){
|
||||
if(!$tw.utils.hop(values,value)) {
|
||||
values[value] = true;
|
||||
results.push(list ? value : title);
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
});
|
||||
return results;
|
||||
|
|
Ładowanie…
Reference in New Issue