Hi,

because I had this issue a while ago and I am currently refactoring my code 
and creating helper functions I just wanted to publish one of my util 
functions that easily lets you filter on a given subset. Doesn't work with 
IE8 because of isArray() ...well who cares? :)

  /**
   * This function facilitates to check whether a list of tiddlers
   * matches a certain filter.
   *
   * @tRefs a hashmap or an array of tiddler references (titles)
   * @filter a filter expression (string) or a compiled filter
   */
  utils.getMatches = function(tRefs, filter) {
    
    var source = function(iterator) {
      if(Array.isArray(tRefs)) {
        for(var i = 0; i < tRefs.length; i++) {
          var tObj = $tw.wiki.getTiddler(tRefs[i]);
          iterator(tObj, tRefs[i]);
        }
      } else if(typeof tRefs == "object") {
        for(t in tRefs) {
          var tObj = $tw.wiki.getTiddler(t);
          iterator(tObj, t);
        }
      } else return [];
    };
    
    if(typeof filter == "string") {
      var filter = $tw.wiki.compileFilter(filter);
    }
    
    return filter.call($tw.wiki, source);
        
  };



-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to tiddlywikidev+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywikidev@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/d/optout.

Reply via email to