javascript - 伸手党来了,handlebars怎么判断值是否包含某个字符串
ringa_lee
ringa_lee 2017-04-11 13:05:57
0
2
301

抱歉,着急用,我又来了。
我想判断某个url({{vediourl}})是否包含.mp4 .ogg 应该怎么写? 应该是要写helper了?

多谢。

ringa_lee
ringa_lee

ringa_lee

répondre à tous (2)
Peter_Zhu
Handlebars.registerHelper('isContain', function(url, options) { if (url.indexOf('.mp4')>=0 || url.indexOf('.ogg')>=0) { return options.fn(this); } return options.inverse(this); });

判断也可以用楼上的正则

使用就像这样

{{#isContain vediourl}} ... {{else}} ... {{/isContain }}
    阿神
    /\.mp4|\.ogg/.test(url)
      Derniers téléchargements
      Plus>
      effets Web
      Code source du site Web
      Matériel du site Web
      Modèle frontal
      À propos de nous Clause de non-responsabilité Sitemap
      Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!