在 Kanso 中使用 underscore.js

发布于 2024-12-16 12:05:21 字数 339 浏览 5 评论 0原文

Kanso.js 是一个可以让您轻松构建 couchapps 的工具。正如在文档中可以看到的,它包含 underscore.js 模块。

但是我怎样才能在列表视图中准确地使用 underscore.js 方法呢?我必须先要求它吗?例如,我一直在使用 union 方法:

var newArray = oldArray1.union(oldArray2)

or

var newArray = union(oldArray1, oldArray2)

但是,Kanso 在通过 HTTP 请求列表时不断引发类型错误。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌辣 2024-12-23 12:05:21

首先 require 文件顶部的 underscore 模块。如果您位于 Kanso 的 dev 分支(版本 0.0.8),它看起来像这样:

_ = require('underscore')._;

在 Kanso 0.0.7 中,它看起来像这样:

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

然后调用 union来自下划线对象

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

编辑:

Kanso 0.2.1(撰写本文时的当前版本)中,下划线有自己的包。使用方法如下:

  1. kanso 中添加 下划线 作为依赖项。 json 文件。

    “依赖项”:{
        ...
        “下划线”:空
    }
    
  2. 在项目目录中运行kanso install

  3. 模块中需要下划线

    _ = require('下划线')._;
    

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')._;
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文