【问题标题】:Jade: each val in times returns "no such function: val"Jade:每个 val 都返回“no such function: val”
【发布时间】:2015-11-27 00:56:00
【问题描述】:

我有以下玉:

template(name='hello')
    button(class="ui grey basic button", id="clickme")
        i(class="sun icon")
        | Times
    div(class="ui list")
        each val in times
            div.item= val

其中 times 是从 JS 辅助方法调用的会话变量。

我正在运行 Meteor 服务器,使用 Semantic-UI 作为我的设计框架。 当我尝试使用这个 Jade 时,页面检查器控制台(在 Chrome 中)返回

Uncaught Error: No such function: val

我不确定要解决什么问题,因为我严格按照 Jade(和 Meteor-Jade)文档进行操作。

谢谢!

【问题讨论】:

  • 可以提供你的js代码吗?
  • 该错误似乎表明 val 函数没有作用域,因此可以读取它。 JS 代码在查看问题出在哪里/是什么方面肯定会很有用。

标签: node.js coffeescript pug


【解决方案1】:

each 不适用于in。试试:

玉:

div(class="ui list")
  each times
    div.item= val

Js:

if (Meteor.isClient) {
  Session.set('times', [{val: 'value1'}, {val: 'value2'}]);

  Template.hello.helpers({
    times: function () {
      return Session.get('times');
    }
  });
}

或者如果你的 Session 变量中有一个数组而不是对象,你可以使用this:

玉:

div(class="ui list")
  each times
    div.item= this

Js:

if (Meteor.isClient) {
  Session.set('times', ['value1', 'value2']);
  ...
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-06
    • 2016-12-01
    • 2011-09-10
    • 2017-10-08
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    相关资源
    最近更新 更多