首页 > 解决方案 > Aframe + Meteor - 向实体添加条件自定义组件

问题描述

标签: meteoraframe

解决方案


已解决这是我的原件,它不起作用。

在 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}}

它只允许 true 或 false 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}}

推荐阅读