Is it possible to use function in Handlebars #if?

后端 未结 4 1814
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-05 13:37

I have a controller object that\'s like:

MyApp.objController = Ember.ArrayController.create({
  init: function(data) {
    data.isValid = function() {
      retu         


        
4条回答
  •  旧时难觅i
    2021-02-05 14:07

    Try this:

      {{#each subsites}} {{#if this}}
    • {{{WhatIsTheSiteFor this}}}
    • {{else}}
    • no found
    • {{/if}} {{/each}}

    The helper function WhatIsTheSiteFor:

    Handlebars.registerHelper('WhatIsTheSiteFor', function(siteName) {
      var subSiteName = '',
          siteNameStr = '';
    
      $.each(siteName, function(i, item) {
        siteNameStr += item;
        return siteNameStr;
      });
    
      if(siteNameStr === 's.gbin1.com') {
        subSiteName = 'GB搜索引擎';
      }
      else if (siteNameStr === 'm.gbin1.com') {
        subSiteName = 'GB手机阅读';
      }
      else if (siteNameStr === 'rss.gbin1.com') {
        subSiteName = 'RSS消息订阅';
      }
    
      return subSiteName;
    });
    

    A demo can be found here: http://www.gbin1.com/gb/networks/uploads/71bb1c1e-0cd3-4990-a177-35ce2612ce81/demo6.html

提交回复
热议问题