为什么 Aframe 的 dependencies 属性不起作用?
Why doesn't Aframe's dependencies attribute not working?
我有以下使用组件初始化实体的简单示例:
<!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>
这是来自 Aframe 关于组件和依赖项的文档
dependencies: allows for control on ordering of component initialization if a component depends on one or more other components. Component names specified in the dependencies array will be initialized left-to-right before initializing the current component. If the dependency have other dependency components, those other dependency components will be ordered in the same manner.
我的问题是为什么这段代码不起作用。该代码按预期生成 a-entity
但未附加任何组件。我希望看到 a、b 和 c 附加到我的实体。我做错了什么?
看起来如果您不为 setAttribute 提供值,它就会被忽略。
试试 aEntity.setAttribute('a', '');
。
控制台应显示:<a-entity c="" b="" a="" position="" rotation="" scale="" visible=""></a-entity>
<!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>
我有以下使用组件初始化实体的简单示例:
<!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>
这是来自 Aframe 关于组件和依赖项的文档
dependencies: allows for control on ordering of component initialization if a component depends on one or more other components. Component names specified in the dependencies array will be initialized left-to-right before initializing the current component. If the dependency have other dependency components, those other dependency components will be ordered in the same manner.
我的问题是为什么这段代码不起作用。该代码按预期生成 a-entity
但未附加任何组件。我希望看到 a、b 和 c 附加到我的实体。我做错了什么?
看起来如果您不为 setAttribute 提供值,它就会被忽略。
试试 aEntity.setAttribute('a', '');
。
控制台应显示:<a-entity c="" b="" a="" position="" rotation="" scale="" visible=""></a-entity>
<!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>