2

Kanso.js is a tool to easily let you build couchapps. As can be read in the documentation it includes the underscore.js module.

But how can I exactly make use of the underscore.js methods in, let's say, a list view? Do I have to require it first? For example I have been playing around a but with the union method:

var newArray = oldArray1.union(oldArray2)

or

var newArray = union(oldArray1, oldArray2)

However, Kanso keeps on raising a typeError when requesting the list over HTTP.

nrw
  • 819
  • 2
  • 7
  • 22
Maarten
  • 635
  • 2
  • 8
  • 22

1 Answers1

3

First require the underscore module at the top of your file. If you're on the dev branch of Kanso (version 0.0.8), It looks like this:

_ = require('underscore')._;

In Kanso 0.0.7 it will look like this:

_ = require('kanso/underscore')._;

Then call union from the underscore object

var newArray = _.union(oldArray1, oldArray2);

Edit:

In Kanso 0.2.1 (the current version at the time of writing), underscore has it's own package. Here's how to use it:

  1. Add underscore as a dependency in your kanso.json file.

    "dependencies": {
        ...
        "underscore": null
    }
    
  2. Run kanso install in your project directory.

  3. Require underscore in a module.

    _ = require('underscore')._;
    
nrw
  • 819
  • 2
  • 7
  • 22
  • Hi, @nrw, do you happen to know how this works in more recent Kanso versions? (I don't recall offhand.) Thanks! – JasonSmith May 05 '12 at 23:41
  • @JasonSmith The require statement should look the same as in 0.0.8, you just need to add `underscore` as a dependency and `kanso install` it. I've edited the answer to be a more useful guide. – nrw May 06 '12 at 00:54