【问题标题】:Aframe + Meteor - Add a conditional custom component to an entityAframe + Meteor - 向实体添加条件自定义组件
【发布时间】:2019-05-12 03:29:37
【问题描述】:
<a-gltf-model id='playerone' {{#if myplayer playerone}}entitymove{{/if}} src="#myMixBun"> </a-gltf-model>

在 Meteor 中使用 Aframe,如果 myplayer 的值为“playerone”,我想添加自定义组件“entitymove”。

{{myplayer}}{{myplayer}}的值是“playerone”,所以变量设置正确。但我收到流星错误“A template tag of type BLOCKOPEN is not allowed here”

例如,如果“entitymove”是一个“类”,我想我可以通过以下方式解决这个问题:

<a-gltf-model id='playerone' class={{#if myplayer playerone}}entitymove{{/if}}  src="#myMixBun"> </a-gltf-model>

但由于它是一个组件,我不知道如何修复语法。

【问题讨论】:

    标签: meteor aframe


    【解决方案1】:

    假设这使用 Meteor-Blaze 模板,您需要在引号/双引号内包含 DOM 元素属性的条件:

    <a-gltf-model id='playerone' class="{{#if myplayer playerone}}entitymove{{/if}}"  src="#myMixBun"> </a-gltf-model>
    

    读数:

    http://blazejs.org/guide/spacebars.html

    【讨论】:

      【解决方案2】:

      已解决 这是我的原创,不能用。

      在 main.js 中:

      player = "player not active";
      
      Template.hello.helpers(
        counter() {......
      
      // if player one
      player = "playerone";
      // if player two
      player = "playertwo";
      
      return { myplayer: player };
        }
      

      在 main.html 中:

      // This statement works
      {{counter.myplayer}}....
      
      <a-gltf-model id='playerone' class="{{#if counter.myplayer playerone}}entitymove{{/if}}"  src="#myMixBun"> </a-gltf-model>
      
      <a-gltf-model id='playertwo' class="{{#if counter.myplayer playertwo}}entitymove{{/if}}"  src="#myMixBun"> </a-gltf-model>
      

      我认为这有两个问题:

      1) 空格键似乎不喜欢带有比较的 if 语句?:

      {{#if counter.myplayer playertwo}}
      

      只允许真假if语句?如:

      {{#if counter.player1}}
      

      2) 我的 aframe 自定义组件实际上不是一个类,所以我不能将流星 #if 语句放在实体中。

      我将代码更改为以下代码,现在可以使用:

      将 main.js 更改为:

      playerone ="";
      playertwo ="";
      
      // if player one
           playerone = "true";
          playertwo = "";
      
      // if player two
           playerone = "";
          playertwo = "true";
       return { player1: playerone, player2: playertwo};
        }
      

      将 main.html 更改为:

      // These statements work
      {{#if counter.player1}}player1 is true{{/if}}
      {{#if counter.player2}}player2 is true{{/if}}....
      
      {{#if counter.player1}}
       <a-gltf-model id='playerone' entitymove   src="#myMixBun" ></a-gltf-model> 
       <a-gltf-model id='playertwo'   src="#myMixBun" ></a-gltf-model> 
       {{/if}}
      
        {{#if counter.player2}}
       <a-gltf-model id='playerone'  src="#myMixBun" ></a-gltf-model> 
       <a-gltf-model id='playertwo' entitymove   src="#myMixBun" ></a-gltf-model> 
       {{/if}}
      

      【讨论】:

        猜你喜欢
        • 2015-07-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-13
        • 2019-10-11
        • 2012-11-11
        • 2011-04-27
        相关资源
        最近更新 更多