2017-10-27 14 views
1

私は、ドラフト・エディタを順序付けられていないリストとして事前に設定したい文字列の配列を持っています。 は、ここでは、コードです:順序付けられていないリストを持つDraft.jsエディタを開始

const content = ContentState.createFromText(input.join('*'), '*') 
const editorState = EditorState.createWithContent(content) 
this.setState({ 
    editorState: RichUtils.toggleBlockType(editorState, 'unordered-list-item' 
}) 

これは、配列の最初のエントリのための箇条書き項目をのみ作成されますが、他の項目はblockstyleを継承されていません。

アイデア?

答えて

0

コンストラクタnew ContentBlock()を使用してContentBlockの配列を作成できます。 ContentState.createFromBlockArrayで初期エディタ状態を生成します。このjsfiddleを見てください - http://jsfiddle.net/levsha/uy04se6r/

constructor(props) { 
    super(props); 
    const input = ['foo', 'bar', 'baz']; 

    const contentBlocksArray = input.map(word => { 
    return new ContentBlock({ 
     key: genKey(), 
     type: 'unordered-list-item', 
     characterList: new List(Repeat(CharacterMetadata.create(), word.length)), 
     text: word 
    }); 
    }); 

    this.state = { 
    editorState: EditorState.createWithContent(ContentState.createFromBlockArray(contentBlocksArray)) 
    }; 
} 
関連する問題