2016-03-29 38 views
3

我有Meteor項目,它使用froala:編輯器 - 反應包爲了設置用戶關於我的領域。Meteor froala:編輯器反應式保存在數據的變化

這裏是我的模板的js代碼:

Template.profile.helpers({ 
    getAbout: function() { 
    return Meteor.user().profile.about; 
    }, 
    doSave: function (e, editor) {   
    // Get edited HTML from Froala-Editor 
    var newHTML = editor.getHTML(); 
    // Do something to update the edited value provided by the Froala-Editor plugin, if it has changed: 
    if (!_.isEqual(newHTML, Meteor.user().profile.about)) { 
     Meteor.call("updateTestimony", Meteor.userId(), newHTML); 
    } 
    return false; // Stop Froala Editor from POSTing to the Save URL 
    } 
} 

這裏是我的模板的html代碼:

<template name="profile"> 
    <div> 
    {{> froalaReactive _onbeforeSave=doSave _value=getAbout}} 
    </div> 
</template> 

它應該保存爲價值變動(我希望)。 但我在線var newHTML = editor.getHTML();有錯誤,我也嘗試var newHTML = editor.html.get(true);。這兩個都會導致無法讀取html或getHTML屬性的錯誤。我希望這只是一個語法錯誤,我需要別的東西,但是這裏有什麼問題?

回答

0

Per the plugin docs,嘗試:

var newHTML = editor.html.get(true /* keep_markers */); 

如果不工作,你可能使用不同的版本。在這種情況下,請提供以下語法一個鏡頭:從官方文檔here

var newHTML = $('.your_selector').editable('getHTML', true, true); 

var newHTML = $('.your_selector').froalaEditor('html.get', true); 

,多看this question