我是新手做出反应,所以我对此并不了解.我试图向li添加一个单击处理程序,但该函数似乎未定义?
var ActivityList = React.createClass({
getInitialState: function() {
return {name:"test"};
},
handleClick:function(e){
console.log(e.target.name);
},
render:function(){
return (
<ul>
{this.props.data.map(function(game){
return <li onClick={this.handleClick} name={game.name}>{game.name}</li>;
})
}
</ul>);
}
});
Run Code Online (Sandbox Code Playgroud)
我想知道是不是因为我在这里找错了?
几天前,我尝试创建一个服务器 - 客户端或客户端服务器作为实验来了解使用线程的套接字,但后来有人告诉我应该使用swingWorker.我做了一些研究如何使用并在实践中实现它但它仍然无效.swingWorker线程看起来不像它正在运行,即使我得到一个连接并使用.excute().如果你们可以帮助发现我做错了哪个会很棒.SwingWorker类位于startSever()和startClient()方法中.
private void startServer() {
SwingWorker <Void, String> runningServer = new SwingWorker<Void, String>(){
protected Void doInBackground() {
try {
listeningSocket = new ServerSocket(port);
System.out.println("waiting for connection");
connection = listeningSocket.accept();
connected = true;
System.out.println("Connected");
String incomeMessage =null;
while(connected){
inStream = connection.getInputStream();
inDataStream = new DataInputStream(inStream);
if (myMessage !=null){
outStream = connection.getOutputStream();
outDataStream = new DataOutputStream(outStream);
outDataStream.writeUTF(myMessage);
}
if((incomeMessage = inDataStream.readUTF())!=null){
clientMessage = incomeMessage;
publish(clientMessage);
incomeMessage =null;
}
}
} catch (IOException e) {
clientMessage = "Connection Lost";
}
return …Run Code Online (Sandbox Code Playgroud) 我正在尝试在打字稿中访问“ naturalWidth”,但是如果遇到编译错误或在“ naturalWidth”下出现红线。因为$(“#contentImg”)。height())在JavaScript和TypeScript中为我返回0,所以我无法操作图像。图像尺寸不一。如果我用javascript做就可以了。我试过了;
document.getElementById('contentImg').naturalWidth;
$("#contentImg")[0].naturalWidth.
Run Code Online (Sandbox Code Playgroud)
这适用于JavaScript,但不适用于TypeScript。有没有一种方法可以获取naturalWidth / Height?