如何在JavaScript中使用对象参数

时间:2020-04-09 07:43:41

标签: javascript

我几乎不熟悉javascript,并尝试基于office.js开发一些Word插件。 我想为给定的XML结构创建“内容控件”。我已经有一个递归函数来迭代xml。

现在,我添加了一些用于插入内容控件的新行。这很麻烦,而且我总是得到有关我的对象(参数)不支持属性或方法“ getRange”的信息。该对象本身是office.js的一部分,并已由Microsoft定义。我相信在将其作为参数处理时,对象会丢失其自身的信息...

当前,我正在Word中使用“脚本实验室”加载项对此进行测试。

函数调用

addChildren($(xmlDoc).find("GetProfile"), $(rootCC));

功能

function addChildren($parent, $contentControl) {
  // ERROR is raising here calling the getRange
  var range = $contentControl.getRange("End")

  $parent.contents().each(function (i, child, contentControl) {
    switch (child.nodeType) {
      case 1:
        // element node
        console.log(child.nodeName);
        var range = contentControl.getRange("End")
        contentControl = range.insertContentControl();
        contentControl.tag = child.nodeName
        contentControl.title = child.nodeName
        contentControl.appearance = "Tags"
      case 2:  
        // attribute node
      case 3:
        // text node
        console.log(child.nodeValue);
        //contentControl.insertText(child.nodeValue,"Replace")
      case 8:
        // comment node
    }
    addChildren($(child), $(contentControl));
  });
}

0 个答案:

没有答案
相关问题