【问题标题】:What is the jade syntax to access variables in inline javascript?访问内联javascript中的变量的jade语法是什么?
【发布时间】:2018-05-04 17:37:33
【问题描述】:

我所有的语法尝试都失败了,关于这个特殊案例的文档很难找到,也许你知道得更好。

.factsheet(ng-repeat="factsheet in factsheets)
    a(ng-href="{{factsheet.link}}", onclick="aFunction('click', {{factsheet.title}})")

ng-href="{{factsheet.link}}", 就像一个魅力。 {{factsheet.title}} 是无法访问的变量。

我试过了

factsheet.title

还有那个

#{factsheet.title}

还有这个

"{{factsheet.title}}"

还有其他绝望的尝试……

'{{factsheet.title}}', "#{{factsheet.title}}"

没有任何效果,虽然我可以在内联 JS 之外轻松访问 title 属性

h2 {{factsheet.title[currentLang]}} // no worries

【问题讨论】:

    标签: angularjs pug


    【解决方案1】:

    K,所以在阅读了类似的问题之后,尤其是 this one,我认为这不是可行的方法,最终像这样使用 ng-click:

    .factsheet(ng-repeat="factsheet in factsheets)
        a(ng-href="{{factsheet.link}}", ng-click="aFunction('click', factsheet.title)")
    

    不管怎样,少用内联 JS 总是一件好事!

    【讨论】:

      猜你喜欢
      • 2011-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-31
      • 1970-01-01
      • 2013-04-06
      相关资源
      最近更新 更多