函数是未定义的,如果它是之前声明的(Function is undefined althoug it is declared right before)
我有一个ToDo List App,用来学习React Native。 当我尝试将clickhandler传递给子项时,它表示clickhandler函数未定义。
这是相关的代码。
constructor(props) { super(props) this.handleTodoPress = this.handleTodoPress.bind(this) } handleTodoPress (event) { console.warn('Press handled') } renderItem ({section, item}) { return <TodoItem onItemPress={this.handleTodoPress} title={item.title} description={item.description} completed={item.completed} /> }
如果我在
renderItem
记录handleTodoPress
,它显示为未定义。 这是为什么?I have a ToDo List App I am creating to learn React Native. When I try to pass a clickhandler to the child item, it says that the clickhandler-function is undefined.
Here is the relevant code.
constructor(props) { super(props) this.handleTodoPress = this.handleTodoPress.bind(this) } handleTodoPress (event) { console.warn('Press handled') } renderItem ({section, item}) { return <TodoItem onItemPress={this.handleTodoPress} title={item.title} description={item.description} completed={item.completed} /> }
If I log
handleTodoPress
inrenderItem
it shows up as undefined. Why is that?
原文:https://stackoverflow.com/questions/49739350
最满意答案
你应该使用CSS而不是正则表达式。
例如:
"[id*=name]"
- 选择id
中具有name
所有元素。
"[id*=name] a, [id*=desc] a"
- 选择所有具有包含name
或desc
的id
父元素的值。You should use css instead of regex.
For example:
"[id*=name]"
- selects all elements with that havename
inid
.
"[id*=name] a, [id*=desc] a"
- selects alla
elements that have parent with anid
that containsname
ordesc
in his value.
相关问答
更多-
Goutte提取带有标签的文字(Goutte extract text with tags)[2022-08-12]
你可以使用html()函数 http://api.symfony.com/4.0/Symfony/Component/DomCrawler/Crawler.html#method_html 喜欢这个 $descriptions = $crawler->filter('element.class')->each(function($node) { return $node->html(); }) 你可以使用strip_tags PHP函数来清理它 http://php.net/manual/fr/f ... -
动态正则表达式捕获(Dynamic regex to capture)[2022-05-17]
实际上,如果所有查询都是这样的,只有可变数量的列,您可以使用一个简单的正则表达式来获取字段名称: (\w+)\W*=\W*['"].+?(?!\\)['"], 这是一个例子 。 这是它的作用: 它捕获一个或多个单词字符,如果后跟: 零个或多个空白字符 一个等号 零个或多个空白字符(再次) A '或" (字符串的开头) 一个或多个角色 未转义的'或" 一个逗号 请注意,这确实假设所有值都是字符串。 如果您还需要数字支持,请告诉我。 Actually, if all queries look like thi ... -
你应该使用CSS而不是正则表达式。 例如: "[id*=name]" - 选择id中具有name所有元素。 "[id*=name] a, [id*=desc] a" - 选择所有具有包含name或desc的id父元素的值。 You should use css instead of regex. For example: "[id*=name]" - selects all elements with that have name in id. "[id*=name] a, [id*=desc] a" - ...
-
在Goutte图书馆内进行了深入的搜索后,我找到了一种方法,我想分享。 由于Goutte是一个功能强大的库,但文档非常复杂。 通过(Goutte> Guzzle) 解析JSON 只需获得需要的输出页面并将json存储到数组中。 $client = new Client(); // Goutte Client $request = $client->getClient()->createRequest('GET', 'http://***.json'); /* getClient() for takin ...
-
Guzzle / Goutte - 基本刮擦 - 将变量传递给请求(Guzzle/Goutte - Basic scrape - passing variable to request)[2023-09-22]
尝试: $crawler->filter('.flash-error')->each(function ($node) use (&$x) { echo $x; print $node->text() . "\n"; }); 如果您不需要在该功能中更改它,则可以删除& 。 有关在匿名函数内继承父变量的参考。 Try: $crawler->filter('.flash-error')->each(function ($node) use (&$x) { echo $x; pr ... -
据我所知,你的问题是获取表单元素,为什么你需要按钮来做这个? 您可以通过id查询表单,即
-
正则表达式 应匹配您的输入字符串 我认为这不是最好的主意,但有一点,你可以使用很多空格,也可以使用任意空格。 如果我是你,我会研究html解析器库。 The regular expressions should match your ...
-
对于任何涉及此问题的人。 它简单到过滤到链接然后执行类似$node->filter('.classname or #ID')->attr('data-original-title') 。 For anyone else that comes accross this issue. Its as simple as filtering down to the link and then doing something like $node->filter('.classname or #ID')->attr( ...
-
您还必须在匹配之前和之后替换字符串: .*?oID=(\d+).* 命令: $string = ''; var_dump(preg_replace('/.*?oID=(\d+).*/','Out ...
-
我发现,深入研究类Symfony \ Component \ DomCrawler \ Crawler文档 public string html() Returns the first node of the list as HTML. Return Value string The node html 这符合我的预期。 将return dd($crawler)转换为return ($crawler->html())产生: [{“id”:1,“group_name”:“Co ...