0

提示用户将我的库中的文档实例复制到他自己站点中的库中的最佳(主观的..我知道。对不起!)方法是什么?我是一名管理员,拥有一些我创建得太频繁而无法为其设置特定内容类型的 Word 文档。所以我创建了一个库,其中包含一些单词模板供他们复制(最重要的是:包括元数据,除了修改/创建的字段)。

我已经尝试了一些 javascript/jquery 方法,我将它们放在显示表单上,并带有一个文本框,允许他们输入他们的库 url 以及他们想要制作多少份副本,但这似乎不起作用,因为我会的。实现这一目标的最有效方法是什么?使用事件处理程序?如果是这样,有没有办法将其中一个与功能区上的自定义按钮相关联(我只将这些按钮与 js 功能相关联)?

我尝试使用的 javascript 函数示例:

function copyItem() {
    var itemurl = $("#copyFrom").val();
    var dst = $("#copyTo").val();

    $().SPServices({
        operation: "GetItem",
        Url: itemurl,
        async: false,
        completefunc: function (xData, Status) {
            itemstream = $(xData.responseXML).find("Stream").text();
            itemfields = "";
            $(xData.responseXML).find("FieldInformation").each(function(){
                itemfields+=$(this).get(0).xml;
            });;

        }
    });

    $().SPServices({
        operation: "CopyIntoItems",
        SourceUrl: itemurl,
        async: false,
        DestinationUrls: [dst],
        Stream: itemstream,
        Fields:itemfields,
        completefunc: function (xData, Status) {
            var error = $(xData.responseXML).find("CopyResult").first().attr("ErrorCode");
        }
    }
}

调用者:

  <label>from:</label><input type="text" value="" id="copyFrom" maxlength="255">
    <label>to:</label><input type="text" value="" id="copyTo" maxlength="255">
    <input type="button" onclick="copyItem();" value="Copy">

注意:我现在没有在这些文本框中输入任何值,因为我手动将它们输入到 itemurl 和 dst 中。但是控制台说:

属性“copyItem”的值为 null 或未定义,而不是 Function 对象。

4

1 回答 1

1

不建议使用“async:false”。最好进行异步调用并将第二个SPServices插入到第一个中。

您的第二个也缺少一个右括号SPServices

最后,“字段”必须是一个数组(http://msdn.microsoft.com/en-us/library/copy.copy.copyintoitems.aspx)。

我尝试了下面的代码,它对我有用:

var srcurl="http://my.sharepoint.com/aymeric_lab/Shared%20Documents/879258.jpeg";
var desturl="http://my.sharepoint.com/aymeric_lab/Shared%20Documents/879258_copy.jpeg";
$().SPServices({
  operation: "GetItem",
  Url: srcurl,
  completefunc: function (xData, Status) {
    var itemstream = $(xData.responseXML).find("Stream").text();
    var itemfields = [];
    $(xData.responseXML).find("FieldInformation").each(function(){
      itemfields.push($(this).get(0).xml);
    });

    $().SPServices({
      operation: "CopyIntoItems",
      SourceUrl: srcurl,
      DestinationUrls: [ desturl ],
      Stream: itemstream,
      Fields:itemfields,
      completefunc: function (xData, Status) {

      }
    })
  }
});
于 2014-02-25T09:03:59.137 回答