【问题标题】:Jade conditionals inside the script tag脚本标签内的翡翠条件
【发布时间】:2014-03-19 00:44:57
【问题描述】:

我正在向 Jade 模板添加一些 Javascript,我遇到的问题是代码重复,因为我无法在脚本标签内执行任何 Jade 条件。无论如何,下面的代码。

if streamingType == 'HLS_IOS'
    script
        :coffee(bare=true)
         window.$j = jQuery
         window.player = new HtmlPlayer $j('#wrapper')
         player._loadVideoAt '#{url}'
else
    script
        :coffee(bare=true)
        window.$j = jQuery
        window.player = new FlashPlayer $j('#wrapper'), '#{flashPlayerId}'
        player._loadVideoAt '#{url}'`

【问题讨论】:

    标签: javascript node.js pug conditional


    【解决方案1】:

    您可以在最近的翡翠版本中使用脚本标签内的条件:

    script
        | window.$j = jQuery;
        if streamingType == 'HLS_IOS'
            | window.player = new HtmlPlayer($j('#wrapper'));
        else
            | window.player = new FlashPlayer($j('#wrapper'), '#{flashPlayerId}');
        | player._loadVideoAt('#{url}');
    

    遗憾的是,我没有找到同时使用条件和过滤器的任何方法,因此您可能不得不编写普通的 javascript。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 2012-12-17
      • 1970-01-01
      • 1970-01-01
      • 2012-03-18
      • 2014-01-08
      • 1970-01-01
      相关资源
      最近更新 更多