2015-03-19 83 views
1

我想在我的Rails應用程序中使用的史詩編輯器,但問題是它不能看到我的文字區域,雖然我指定其ID史詩編輯器無法訪問我的textarea軌

這裏的配置

<script type="text/javascript"> 
 
    var opts = { container: 'epiceditor' 
 
     , basePath: '' 
 
     , textarea: 'my-edit-area' 
 
     , clientSideStorage: true 
 
     , localStorageName: 'epiceditor' 
 
     , useNativeFullscreen: true 
 
     , file: { name: null 
 
     , defaultContent: '' 
 
      , autoSave: 100 // Set to false for no auto saving 
 
      } 
 
     , theme: { base: '<%= asset_path("base/epiceditor.css") %>' 
 
      , preview: '<%= asset_path("preview/github.css") %>' 
 
      , editor: '<%= asset_path("editor/epic-light.css") %>' 
 
      } 
 
     , focusOnLoad: false 
 
     , shortcut: { modifier: 18 // alt keycode 
 
      , fullscreen: 70 // f keycode 
 
      , preview: 80 // p keycode 
 
      } 
 
     , string: { togglePreview: 'Toggle Preview Mode' 
 
      , toggleEdit: 'Toggle Edit Mode' 
 
      , toggleFullscreen: 'Enter Fullscreen' 
 
      } 
 
     , parser: typeof marked == 'function' ? marked : null 
 
     , autogrow: false 
 
     , button: { fullscreen: true 
 
      , preview: true 
 
      , bar: "auto" 
 
      } 
 
     } 
 
    var editor = new EpicEditor(opts).load(); 
 
</script>

和這裏的視圖文件

<div id='epiceditor'> 
 
    <%= text_area_tag(f['name'],f['value'], size: '20x5', class: 'form-control', id: 'my-edit-area') %> 
 
</div>

在控制檯它給了我這個

Uncaught TypeError: Cannot read property 'value' of null

+0

嘗試將其添加到$(document).ready中,並且還有 - 史詩般的reditor並不需要textarea在

之內 - 如果你必須從textarea保存數據 - 你必須使用js來獲取它,你的隱藏輸入(例如) – Legendary 2015-03-19 10:48:05

回答

2

試一下(我想,烏爾腳本運行烏爾HTML載入前)

$(document).ready(function() { 
    // yours script here 
}); 

<div id='epiceditor'></div> 

對於來自epiceditor保存數據 - u有使用js從epiceitor獲取數據,並放入hidden_​​input