Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么';t一帧';s的依赖项属性不工作?_Javascript_Aframe_Virtual Reality - Fatal编程技术网

Javascript 为什么';t一帧';s的依赖项属性不工作?

Javascript 为什么';t一帧';s的依赖项属性不工作?,javascript,aframe,virtual-reality,Javascript,Aframe,Virtual Reality,我有以下使用组件初始化实体的简单示例: <!DOCTYPE html> <html> <head> <title>Hello, WebVR! - A-Frame</title> <meta name="description" content="Hello, WebVR! - A-Frame"> <script src="https://aframe.io/releases/0.7.0/af

我有以下使用组件初始化实体的简单示例:

<!DOCTYPE html>
<html>
  <head>
    <title>Hello, WebVR! - A-Frame</title>
    <meta name="description" content="Hello, WebVR! - A-Frame">
    <script src="https://aframe.io/releases/0.7.0/aframe.min.js"></script>
  </head>
  <script>
    AFRAME.registerComponent('a', {
      dependencies: ['b']
    });
    // Initializes second.
    AFRAME.registerComponent('b', {
      dependencies: ['c']
    });
    // Initializes first.
    AFRAME.registerComponent('c', {});
  </script>
  <body>
    <a-scene>
    </a-scene>
  </body>
  <script>
    sceneEl = document.querySelector('a-scene');
    aEntity = document.createElement('a-entity');
    aEntity.setAttribute('a');
    sceneEl.appendChild(aEntity);
  </script>
</html>

你好,WebVR人字架
AFRAME.registerComponent('a'{
依赖项:['b']
});
//初始化第二个。
AFRAME.registerComponent('b'{
依赖项:['c']
});
//首先初始化。
注册表组件('c',{});
sceneEl=document.querySelector('a-scene');
aEntity=document.createElement('a-entity');
aEntity.setAttribute('a');
sceneEl.appendChild(aEntity);
这是关于组件和依赖关系的Aframe文档

依赖项:如果组件依赖于一个或多个其他组件,则允许控制组件初始化的顺序。在初始化当前组件之前,将从左到右初始化依赖项数组中指定的组件名称。如果依赖项具有其他依赖项组件,则这些其他依赖项组件将以相同的方式排序


我的问题是为什么这个代码不起作用。代码按预期生成
a-实体
,但未连接任何组件。我希望看到a、b和c附属于我的实体。我做错了什么?

看起来,如果不为setAttribute提供值,它将被忽略

尝试
aEntity.setAttribute('a','')取而代之

控制台应显示:


你好,WebVR人字架
AFRAME.registerComponent('a'{
依赖项:['b']
});
//初始化第二个。
AFRAME.registerComponent('b'{
依赖项:['c']
});
//首先初始化。
注册表组件('c',{});
sceneEl=document.querySelector('a-scene');
aEntity=document.createElement('a-entity');
aEntity.setAttribute('a','');
sceneEl.appendChild(aEntity);
控制台日志(aEntity)

我也看到了
.setAttribute('foo',true)
在使用中,但我还没有查看属性解析器以确定哪一个更有效。
<!DOCTYPE html>
<html>
  <head>
    <title>Hello, WebVR! - A-Frame</title>
    <meta name="description" content="Hello, WebVR! - A-Frame">
    <script src="https://aframe.io/releases/0.7.0/aframe.min.js"></script>
  </head>
  <script>
    AFRAME.registerComponent('a', {
      dependencies: ['b']
    });
    // Initializes second.
    AFRAME.registerComponent('b', {
      dependencies: ['c']
    });
    // Initializes first.
    AFRAME.registerComponent('c', {});
  </script>
  <body>
    <a-scene>
    </a-scene>
  </body>
  <script>
    sceneEl = document.querySelector('a-scene');
    aEntity = document.createElement('a-entity');
    aEntity.setAttribute('a', '');
    sceneEl.appendChild(aEntity);
    console.log(aEntity)
  </script>
</html>