我想设置我的Tinymce值内容。 我的HTML代码是:
<div class="form-group">
<label for="activity">Activity</label>
<label class="activity-error pull-right text-danger"></label>
<textarea name="activity" id="activity" class="mceEditor"> </textarea>
</div>
我的脚本是:
tinyMCE.get('activity').setContent('<p>hello world</p>');
但是没有用。 这是怎么回事?请帮我。预先谢谢你。
答案 0 :(得分:0)
您遇到的问题(基于Fiddle)是您在初始化之前试图使用TinyMCE API与编辑器进行交互。我在这里调整了您的小提琴:
http://fiddle.tinymce.com/gvgaab/3
网络是您试图在TinyMCE完成初始化之前调用/** the trick is with DeviceEventEmitter **/
import { DeviceEventEmitter } from 'react-native';
const initialRouteName = "FluxObservations";
const MyTabView = TabNavigator(
{
FluxObservations: { screen: FluxObservations },
Projects: { screen: Projects },
NewObservation: { screen: NewObservation},
Explorer: { screen: Explorer },
Profil: { screen: Profil }
},
{
swipeEnabled: false,
initialRouteName: initialRouteName,
tabBarPosition: "bottom",
tabBarOptions: { ... },
navigationOptions: {
tabBarOnPress: ({ previousScene, scene, jumpToIndex }) => {
//On each tab change we inject event
DeviceEventEmitter.emit('updateCurrentRouteName', { currentRouteName: scene.route.routeName });
// Keep original behaviour
jumpToIndex(scene.index)
}
}
}
);
const StackView = StackNavigator(
{
global: {
screen: MyTabView,
headerMode: "none",
header: null,
navigationOptions: {
header: null
}
},
Credits: { screen: Credits },
Floristic: { screen: Floristic },
TermsOfUse: { screen: TermsOfUse },
LegalNotice: { screen: LegalNotice },
Options: { screen: Options },
},
{mode: 'modal'}
);
export default class App extends React.PureComponent {
constructor (props) {
super(props);
// emit the event for the first tab opened by default, initialRouteName
DeviceEventEmitter.emit('updateCurrentRouteName', { currentRouteName: initialRouteName });
}
// catching all event for route name change !
listeners = {
update: DeviceEventEmitter.addListener('updateCurrentRouteName', ({ ...currentRouteName }) => {
console.log("MAIN ", currentRouteName) // Perform update
})
}
render() {
return (
<Provider store={store}>
<PersistGate
loading={<ActivityIndicator />}
persistor={persistor}>
<View style={styles.fullScreen}>
<StackView />
</View>
</PersistGate>
</Provider>
);
}
}
。我已经在控制台上记录了结果,您将看到其tinymce.get('content')
。当您尝试在null
上呼叫getContent()
时失败。
TinyMCE提供了一个钩子,可以知道何时完全初始化编辑器,而我更新的Fiddle显示了如何使用它来触发将数据加载到编辑器中。