简体   繁体   中英

How can I use LokiJs in the browser?

I suspect this is a bit of a simple question, as I'm not very experienced with the frontend.

I'm trying to use lokijs as a datastore in a browser app, but I can't get it to run. I have <script src="lib/lokijs/src/loki-angular.js"></script> in my html, and

var db = new loki('test');
var users = db.addCollection('users');
users.insert({
  name: 'joe'
});

console.log(users.data);

in my js as a trivial test. However, I'm getting the error Uncaught ReferenceError: loki is not defined . Please let me know where' I'm going wrong, and I apologize if this is something stupid!

You are not far off. You mention you are referencing loki-angular.js in your html, however you should be referencing lib/lokijs/build/lokijs.min.js or even reference it from a cdn if you don't want to involve npm, I know cdnjs has it.

With that your example should run just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM