【发布时间】:2021-03-15 16:04:17
【问题描述】:
我有一个非常简单的 React 应用程序,它只是用于使用 TinyMCE 编辑角色描述。
它作为一个独立的应用非常好用,但我想在使用 Backbone 的旧版 WebApp 游戏中使用它。
每当我启动 Backbone 应用程序游戏并转到应该呈现新 React 组件的 Backbone 视图时,我都会收到一个简单的错误,上面写着 Error: Invariant Violation: _
控制台或任何地方都没有其他信息。
有什么我可能做错了吗?
这是我使用 TinyMCE 的 React 应用程序:
import React from 'react';
import { Editor } from '@tinymce/tinymce-react';
class CharacterTextApp extends React.Component {
handleEditorChange = (content, editor) => {
console.log('Content was updated:', content);
}
render() {
return (
<Editor
initialValue="<p>Your Character</p>"
init={{
height: 300,
menubar: false,
plugins: [
'lists link image preview',
'media paste help'
],
toolbar:
'undo redo | bold italic | \
alignleft aligncenter alignright | \
indent | help | image |'
}}
onEditorChange={this.handleEditorChange}
/>
);
}
}
export default CharacterTextApp;
这是我尝试在我的 Backbone 视图网页游戏中调用 react 组件的方式:
import Backbone from 'backbone';
import _ from 'underscore';
import template from 'text!./CharacterDescription.html';
import CharacterTextApp from 'new/components/CharacterTextApp';
export default Backbone.View.extend({
className: 'characterData',
template: _.template(template, null, { variable: 'ctx' }),
initialize: function (args) {
this.header = 'Your Character';
},
render: function () {
this.$el.html(this.template({
data: this.model.toJSON(),
header: this.header
}));
this.renderCharacterTextApp();
return this;
},
renderCharacterTextApp() {
this.renderComponent(CharacterTextApp, {
characterId: this.model.get('characterId'),
onUpdate: (newId) => this.model.save('characterId', newId, {wait: true}),
}, '#characterInformation');
},
});
【问题讨论】:
标签: reactjs backbone.js tinymce backbone-views