在我的React.createClass()类的代码中,我有一个getDefaultProps()方法,它返回一个字典,其中initial_text设置为文本值。
getDefaultProps: function()
{
return {
initial_text: "**I am *terribly* " +
...
然后,在render()中,我尝试访问this.props.initial_text:
render: function()
{
var tokenize = function(original)
{
var workbench = original;
var result = [];
while (workbench)
{
if (workbench[0] === '<')
{
length = workbench.indexOf('>');
if (length > -1)
{
length = 1;
}
}
else
{
length = 1;
}
result.push(workbench.substr(0, length));
workbench = workbench.substr(length);
}
return result;
}
var initial_tokens = tokenize(converter.makeHtml(
this.props.initial_text));
Chrome控制台显示:
Uncaught ReferenceError: initial_text is not defined
在默认属性中设置字符串并访问代码以获取字符串需要做什么?