Skip to content

Commit ced33df

Browse files
committed
sync cocos2d#20007 to v4
1 parent 4003802 commit ced33df

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

cocos/2d/CCNode.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -809,22 +809,27 @@ void Node::enumerateChildren(const std::string &name, std::function<bool (Node *
809809

810810
// Remove '//', '/..' if exist
811811
std::string newName = name.substr(subStrStartPos, subStrlength);
812-
812+
813+
const Node* target = this;
814+
813815
if (searchFromParent)
814816
{
815-
newName.insert(0, "[[:alnum:]]+/");
817+
if (nullptr == _parent)
818+
{
819+
return;
820+
}
821+
target = _parent;
816822
}
817823

818-
819824
if (searchRecursively)
820825
{
821826
// name is '//xxx'
822-
doEnumerateRecursive(this, newName, callback);
827+
target->doEnumerateRecursive(this, newName, callback);
823828
}
824829
else
825830
{
826831
// name is xxx
827-
doEnumerate(newName, callback);
832+
target->doEnumerate(newName, callback);
828833
}
829834
}
830835

cocos/2d/CCNode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ class CC_DLL Node : public Ref
794794
* @param name The name to search for, supports c++11 regular expression.
795795
* Search syntax options:
796796
* `//`: Can only be placed at the begin of the search string. This indicates that it will search recursively.
797-
* `..`: The search should move up to the node's parent. Can only be placed at the end of string.
797+
* `/..`: The search should move up to the node's parent. Can only be placed at the end of string.
798798
* `/` : When placed anywhere but the start of the search string, this indicates that the search should move to the node's children.
799799
*
800800
* @code

0 commit comments

Comments
 (0)