如何handleButtonPress在此示例React组件中调用消息映射内部?
import React, { Component } from 'react';
import {View, Text, TouchableOpacity} from 'react-native';
export default class MyComponent extends Component {
constructor(props){
super(props)
this.state = {messages:["THANKS", "MERCI", "GRAZIE"]}
this.myFunc = this.myFunc.bind(this)
this.handleButtonPress = this.handleButtonPress.bind(this)
}
render(){
return (
<View>
<Text>{this.state.message}</Text>
{
this.state.messages.map(function(message, index){
return (
<TouchableOpacity key={index} onPress={function(){ this.handleButtonPress(message) }.bind(this) }>
<Text>Press Me</Text>
</TouchableOpacity>
)
})
}
</View>
)
}
handleButtonPress(message){
console.log("BUTTON WAS PRESSED WITH MESSAGE: " + message)
this.myFunc(message)
}
myFunc(message){
console.log("MY FUNCTION WAS CALLED")
this.setState({message:message})
} …Run Code Online (Sandbox Code Playgroud) 在Ruby中,是否可以从超类方法转换为子类方法而又不影响子类中的代码?我试图避免super在子类中调用。
class SuperClass
def do_something
puts "getting ready..."
# how to then yield back to the subclass do_something method?
puts "done."
end
end
class SubClass < SuperClass
def do_something
# how to first execute the superclass do_something method?
puts "doing something ..."
end
end
Run Code Online (Sandbox Code Playgroud)
所需的功能是专门调用SubClass.do_something并接收以下输出:
“准备...”
“做某事...”
“做完了。”
编辑:
也许真正的问题是:如何干涸下面的代码,删除对来电self.get_ready和self.finish_up所有子类,使用任何红宝石的元编程技术,保持这些类DRY:
class SuperClass
def self.get_ready
puts "getting ready ..."
end
def self.finish_up
puts "done."
end
end
class SubClassA < SuperClass
def self.do_something
self.get_ready …Run Code Online (Sandbox Code Playgroud) 在MySQL group_concat()子句中,我正在尝试对case语句的结果值进行排序.以下查询配置正确things.name排序,但未在同一上下文中排序"非美国"或"未知"值.
SELECT
things.id
,group_concat(DISTINCT
CASE
WHEN things.name <> 'United States' THEN 'Non-US'
WHEN things.name IS NULL THEN 'Unknown'
ELSE things.name
END
ORDER BY name SEPARATOR ', ')
FROM things
GROUP BY things.id
Run Code Online (Sandbox Code Playgroud)
我想做这样的事情,但它不起作用:
SELECT
things.id
,group_concat(DISTINCT
(CASE
WHEN things.name <> 'United States' THEN 'Non-US'
WHEN things.name IS NULL THEN 'Unknown'
ELSE things.name
END) AS new_name
ORDER BY new_name SEPARATOR ', ')
FROM things
GROUP BY things.id
Run Code Online (Sandbox Code Playgroud)
有没有办法按"new_name"排序而不使用子查询/嵌套查询?
我正在尝试使用结构化数据来指定多个组织(见下文)。但谷歌的结构化数据测试工具只能识别每种类型的第一项。
如何列出多个alumniOf项目?
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Organization",
"name": "My Org",
"founder": {
"@type": "Person",
"name":"Me",
"alumniOf":{
"@type": "Organization",
"name": "My Org 1"
},
"alumniOf":{
"@type": "Organization",
"name": "My Org 2"
}
}
</script>
Run Code Online (Sandbox Code Playgroud) es6-class ×1
group-concat ×1
inheritance ×1
javascript ×1
json-ld ×1
mysql ×1
react-native ×1
reactjs ×1
ruby ×1
schema.org ×1
seo ×1
sql ×1
sql-order-by ×1