1

我使用tinymce 已经有一段时间了。并感谢http://github.com/spohlenz/tinymce-rails 但是现在我必须在基于主干轨
的应用程序中包含 tinymce 我已经遵循了 rails 应用程序的所有说明。
试图在 application.js 中的主干文件之前和之后包含 tinymce
我的主干模板

<textarea class="tinymce" id="article_body" rows='40' cols='120' >
  <%= @article.get('body') %>  
</textarea>

但是 tinymce 控件无法初始化。
你可以帮帮我吗?

更新 1我尝试在模板
初始化 tinymce,并且: 在 edit.jst.eco

<textarea class="tinymce" id="article_body<%= @article.get('id') %>" rows='40' cols='120' >
  <%= @article.get('body') %>
</textarea>  
<% tinyMCE.execCommand "mceAddControl", true, "article_body"+@article.get('id')%>

仅在手动刷新 (f5) 后才会显示 texterea 上的控件

更新 2
我尝试将 execCommand 方法添加到我有兴趣在其中显示 tinymce 的视图的渲染方法中:

class Notes.Views.ArticleEdit  
  render: ->  
    $(@el).html(@template(article: @model))  
    tinyMCE.execCommand "mceAddControl", false, "article_body"+@model.get('id')  
    this  

与更新 1 相比没有变化
更新 3
尝试在渲染后绑定 tinymce。使用了 2 种方法:
1)

class Notes.Views.ArticleEdit  
  render: ->  
    $(@el).html(@template(article: @model))  
    setTimeout (->
      tinyMCE.execCommand "mceAddControl", true, "article_body" + @model.get("id")
    ), 100

没有变化。仅在显示刷新 tinymce
2) http://fahad19.tumblr.com/post/28158699664/afterrender-callback-in-backbone-js-views

  class Notes.Views.ArticleEdit extends Backbone.View  
  initialize: ()->  
    _.bindAll this,  "render", "afterRender"  
    _this = this  
    @render = _.wrap(@render, (render) ->  
      render()  
      _this.afterRender()  
      _this  
    )  
    @model.on('change',@render,this)  
    @model.on('destroy',@remove,this)  
  afterRender: ->  
    console.log tinyMCE  
    tinyMCE.execCommand "mceAddControl", true, "article_body" + @model.get("id")  

虽然我得到了控制台输出(正确的 tinymce 对象),但我没有得到 tinymce :(

更新 4
这是github上的项目

更新 5
我弄错了 - 项目仅在路由器中呈现后才出现在 DOM 中。所以我必须编辑 Notes.Routers.Articles#edit 动作

4

1 回答 1

0

要解决我的问题,我必须像这样编辑路由器操作:

edit: (id)->  
    @model = @collection.get(id)  
    view = new Notes.Views.ArticleEdit(model: @model)  
    $('#container').html(view.render().el)  
    el_id = "article_body" + @model.get("id")  
    if (tinyMCE.getInstanceById(el_id)) {   
      tinyMCE.execCommand 'mceFocus', false, el_id  
      tinyMCE.execCommand "mceRemoveControl", false, el_id  
    }  
    tinyMCE.execCommand "mceAddControl", false, el_id  
    tinyMCE.triggerSave()*emphasized text 
于 2013-03-07T11:51:28.003 回答