2

jquery spservices を使用して listitem を更新しようとしています。すべてが機能していますが、href をリッチテキスト フィールドに追加しようとすると機能しません。hrefではなくプレーンテキストのみを更新します。以下はコードです。これは単なるテストであるため、これらの URL はテスト用です。

function fn_UpdateListItem(){
$().SPServices({
operation: 'UpdateListItems',
listName: 'Bedrijven',
ID: 1,
valuepairs: [["Software", "<a href='http://www.google.nl'>its a test.</a>"]],
completefunc: function(xData, Status) {
alert('test complete');
}
});
}

値のペアを次のように変更した場合

valuepairs: [[\"Software\", \"test\"]],

それは機能し、リッチテキストフィールドにテストを入れます。しかし、hrefでは機能しません。誰も修正方法を知っていますか? ありがとうございます

4

3 に答える 3

2

Sharepoint 2010 でも同じ問題が発生しました。この場合は var dfNotes = CKEDITOR.instances.notes.getData(); です。私にはうまくいきませんでした、私はこれを見つけました:

https://msdn.microsoft.com/en-us/library/office/ee658527(v=office.14).aspx

var value = SP.Utilities.HttpUtility.htmlEncode(html); 
編集

Sharepoint 2016 SharePoint On-Premisesでテスト済み、それも機能するので、SharePoint Onlineでも機能するはずです!!

これは私にとってどのように機能したかです:

function AddListItem(html, list) { 
    var value = SP.Utilities.HttpUtility.htmlEncode(html);        
    $().SPServices({
        operation: "UpdateListItems",
        async: false,
        batchCmd: "New",
        listName: list,
        valuepairs: [["Title", 'Title'], ["Content", value]],
        completefunc: function(xData, Status) {
            console.log(Status);
        }
    });

} 
于 2017-03-16T04:01:05.593 に答える
1

You need encode the html code (replace the characters < and > for JavaScript: Escaping Special Characters, &lt; and &gt;; this is an example of some characters), this way you going to have a string available to save in the rich content text field (Notes), when The item is updated your data going to have a html code.

This is the code:

function fn_UpdateListItem(){

    var link = htmlEscape('<a href='http://www.google.nl'>its a test.</a>');

    $().SPServices({
        operation: 'UpdateListItems',
        listName: 'Bedrijven',
        ID: 1,
        valuepairs: [["Software", link]],
        completefunc: function(xData, Status) {
            alert('test complete');
        }
     });
}

//This function makes the magic
function htmlEscape(str) {
    return String(str)
        .replace(/&/g, '&amp;')
        .replace(/"/g, '&quot;')
        .replace(/'/g, '&#39;')
        .replace(/</g, '&lt;')
        .replace(/>/g, '&gt;');
}

Best regards

于 2014-05-16T17:37:25.063 に答える