Hi guys,
I need a bit of help to understand how to access getTiddler method from a
javascript library
When I develop *macro* (module-type) I use this.wiki. filterTiddlers
(...) methods and all works fine when I invoke this macro from a tiddler
script
But I would like to develop a javascript library that is intended to be
used by different macros. This library will need to access a Data Tiddler
(as a DB "backend")
So I created a javascript code and set its module-type to *library*
The code is the following
(function(){
class Hero {
constructor(name, level) {
var stats_tiddler_title = "Stats_report"; // a backend tiddler that
contains the stats reports (as field value)
var stats_tiddler_filter = "[["+stats_tiddler_title+"]]";
var stats_tiddlers = this.wiki.filterTiddlers(stats_tiddler_filter);
this.name = name;
this.level = level;
console.log(" Class created. Value:"+this.level);
}
getName() {
console.log(" getName !!!!!. Name:"+this.name);
}
}
exports.Hero = Hero;
})();
>From my macro javascript I tried to call this library
var Hero = require('$:/plugins/vpl/vpl_test_class.js').Hero;
const hero1 = new Hero('Varg', 1);
But I get the error
Uncaught TypeError: Cannot read properties of undefined (reading
'filterTiddlers')
I'm blocked .... Can someone help & guide me on the proper way to do that ?
Thanks very much for your help
Regards
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/c90c3f62-4bb8-456c-b58b-71c2ba0fdec5n%40googlegroups.com.