我想从另一个类onclick调用静态方法。我有三个组成部分。第一个是,
#include <iostream>
#include <wchar.h>
#include "unicode/ustring.h"
void convertUnicodeStringtoWideChar(const UChar* cuniszSource,
const int32_t cunii32SourceLength,
wchar_t*& rpwcharDestination,
int32_t& destCapacity)
{
UErrorCode uniUErrorCode = U_ZERO_ERROR;
int32_t pDestLength = 0;
rpwcharDestination = 0;
destCapacity = 0;
u_strToWCS(rpwcharDestination,
destCapacity,
&pDestLength,
cuniszSource,
cunii32SourceLength,
&uniUErrorCode);
uniUErrorCode = U_ZERO_ERROR;
rpwcharDestination = new wchar_t[pDestLength+1];
if(rpwcharDestination)
{
destCapacity = pDestLength+1;
u_strToWCS(rpwcharDestination,
destCapacity,
&pDestLength,
cuniszSource,
cunii32SourceLength,
&uniUErrorCode);
destCapacity = wcslen(rpwcharDestination);
}
} //function ends
int main()
{
// a ä Š € ( )
UChar input[20] = { 0x0061, 0x00e4, 0x0160, 0x20ac, 0xd87e, 0xdd29, 0x0000 };
wchar_t * output;
int32_t outlen = 0;
convertUnicodeStringtoWideChar( input, 6, output, outlen );
for ( int i = 0; i < outlen; ++i )
{
std::cout << std::hex << output[i] << "\n";
}
return 0;
}
然后我有另一个组件,我正在加载此组件
import * as React from 'react';
import { Link } from 'react-router';
export var One= React.createClass<any, any>({
getInitialState: function () {
return (
{
name: ""
});
},
statics: {
updateName:function(){
this.setState({name:'jobs changed'});
},
},
render() {
return(
<div >
<span>{this.state.name}</span>
</div>
);
}
});
});
我有第三个组件,点击一个应该调用的静态方法。
import * as React from 'react';
import {One} from './data';
export var Two= React.createClass<any, any>({
render() {
return(
<div >
<One />
</div>
);
}
});
他们在这里给我以下错误:
import * as React from 'react';
import { Link } from 'react-router';
import {One} from './data';
export var Three= React.createClass<any, any>({
render() {
return(
<div >
<Link onClick={One.updateName} >Click Me </Link>
</div>
);
}
请帮忙怎么做?我们可以在静态方法中使用Error:Property 'updateName' does not exist on type 'ClassicComponentClass<any>'
吗?如果没有那么我如何从静态方法更新状态?或者我是否需要在课外使用名称变量,然后使用它来更新名称?
我正在尝试基于此fiddle
答案 0 :(得分:2)
静态方法与实例方法之间的区别
答案 1 :(得分:0)
我意识到静态方法不能拥有自己类的引用。这个问题不是一个有效的问题。