AABB
AlignmentBehavior
ArriveBehavior
AStar
BFS
BoundingSphere
BVH
BVHNode
Cell
CellSpacePartitioning
CohesionBehavior
CompositeGoal
ConvexHull
Corridor
CostTable
DFS
Dijkstra
Edge
EntityManager
EvadeBehavior
EventDispatcher
Behavior
FollowPathBehavior
FuzzyAND
FuzzyCompositeTerm
FuzzyFAIRLY
FuzzyModule
FuzzyOR
FuzzyRule
FuzzySet
FuzzyTerm
FuzzyVariable
FuzzyVERY
GameEntity
Goal
GoalEvaluator
Graph
GraphUtils
HalfEdge
HeuristicPolicyDijkstra
HeuristicPolicyEuclid
HeuristicPolicyEuclidSquared
HeuristicPolicyManhattan
InterposeBehavior
LeftSCurveFuzzySet
LeftShoulderFuzzySet
LineSegment
Logger
MathUtils
Matrix3
Matrix4
MemoryRecord
MemorySystem
MeshGeometry
MessageDispatcher
MovingEntity
NavEdge
NavMesh
NavMeshLoader
NavNode
Node
NormalDistFuzzySet
OBB
ObstacleAvoidanceBehavior
OffsetPursuitBehavior
OnPathBehavior
Path
Plane
Polygon
Polyhedron
PriorityQueue
PursuitBehavior
Quaternion
Ray
RectangleTriggerRegion
Regular
RightSCurveFuzzySet
RightShoulderFuzzySet
SAT
SeekBehavior
SeparationBehavior
SingletonFuzzySet
Smoother
SphericalTriggerRegion
State
StateMachine
SteeringBehavior
SteeringManager
Task
TaskQueue
Telegram
Think
Time
TriangularFuzzySet
Trigger
TriggerRegion
Vector3
Vehicle
Version
WanderBehavior

resolveReferences

解析引用的行为

描述

在onpath属性中找到对其进行引用的所有元素,并将它们替换为对应的DOM元素。

语法

resolveReferences(els, parentEl)

参数说明

参数 描述
els 对onpath属性进行引用的元素集合。
parentEl 元素的直接父级元素。

返回值

无返回值。

示例

<!DOCTYPE html>
<html>
<body>

<div id="parent">
    <div id="item-1" onpath="item-2">item 1</div>
    <div id="item-2">item 2</div>
</div>

<script src="yuka.js"></script>
<script>
    const parentEl = document.getElementById('parent');
    const els = parentEl.querySelectorAll('[onpath]');

    Yuka.OnPathBehavior.resolveReferences(els, parentEl);
</script>

</body>
</html>

在上述示例中,我们定义了两个元素,分别为item-1item-2。其中,item-1onpath属性值为item-2,表示它引用了item-2元素。当我们调用resolveReferences方法后,会解析出item-1元素引用的item-2元素,并将其替换为对应的DOM元素。最终,在页面上呈现出来的结果为:

item 2

需求

需要使用onpath属性来表示元素之间的引用关系。在此基础上,需要将之前被引用的元素替换为实际的DOM元素,以便在页面上呈现出正确的内容。

限制

暂无限制。