当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript JsonStoreService.setIn方法代码示例

本文整理汇总了TypeScript中ng2-json-editor.JsonStoreService.setIn方法的典型用法代码示例。如果您正苦于以下问题:TypeScript JsonStoreService.setIn方法的具体用法?TypeScript JsonStoreService.setIn怎么用?TypeScript JsonStoreService.setIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ng2-json-editor.JsonStoreService的用法示例。


在下文中一共展示了JsonStoreService.setIn方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1:

  splitResult.splits.forEach(split => {
    // handle array insert
    let relativePath = split.path;
    let insertLast = relativePath.findIndex(el => el === '-');
    if (insertLast > -1) {
      let valueToInsert;
      let sliceIndex = insertLast + 1;
      let insertPath = relativePath.slice(0, sliceIndex);
      if (sliceIndex < relativePath.length) {
        let afterInsertPath = relativePath.slice(sliceIndex);
        let stub = {};
        stub[afterInsertPath[afterInsertPath.length - 1]] = split.value;
        for (let i = afterInsertPath.length - 2; i >= 0; i--) {
          let temp = { [afterInsertPath[i]]: stub };
          stub = temp;
        }
        valueToInsert = stub;
      } else {
        valueToInsert = split.value;
      }
      let fullInsertPath = referencePath.concat(insertPath);
      jsonStore.addIn(fullInsertPath, valueToInsert);
    } else {
      let toPath = referencePath.concat(split.path);
      jsonStore.setIn(toPath, split.value);
    }

  });
开发者ID:inspirehep,项目名称:record-editor,代码行数:28,代码来源:commons.ts

示例2: splitPrimitiveReferenceField

export function splitPrimitiveReferenceField(path: Array<any>, value: string, jsonStore: JsonStoreService, keyStore: KeysStoreService) {
  let splitResult = splitReferenceField(value);
  // parent path, ['references', N, 'reference']
  let referencePath = path.slice(0, -2);
  splitResult.splits.forEach(split => {
    // handle array insert
    let relativePath = split.path;
    let insertLast = relativePath.findIndex(el => el === '-');
    if (insertLast > -1) {
      let valueToInsert;
      let sliceIndex = insertLast + 1;
      let insertPath = relativePath.slice(0, sliceIndex);
      if (sliceIndex < relativePath.length) {
        let afterInsertPath = relativePath.slice(sliceIndex);
        let stub = {};
        stub[afterInsertPath[afterInsertPath.length - 1]] = split.value;
        for (let i = afterInsertPath.length - 2; i >= 0; i--) {
          let temp = { [afterInsertPath[i]]: stub };
          stub = temp;
        }
        valueToInsert = stub;
      } else {
        valueToInsert = split.value;
      }
      let fullInsertPath = referencePath.concat(insertPath);
      jsonStore.addIn(fullInsertPath, valueToInsert);
    } else {
      let toPath = referencePath.concat(split.path);
      jsonStore.setIn(toPath, split.value);
    }

  });
  // if all of field is splitted, remove it
  if (!splitResult.unsplitted) {
    let parentPath = path.slice(0, -1);
    // remove even it's parent, if the field is the only element in an array
    if (Number.isInteger(path[path.length - 1]) && jsonStore.getIn(parentPath).size <= 1) {
      jsonStore.removeIn(parentPath);
    } else {
      jsonStore.removeIn(path);
    }
  } else {
    jsonStore.setIn(path, splitResult.unsplitted);
  }
  keyStore.buildKeysMapRecursivelyForPath(jsonStore.getIn(referencePath), referencePath);
}
开发者ID:inspirehep,项目名称:record-editor,代码行数:46,代码来源:commons.ts

示例3:

      .then(linkedReferences => {
        this.jsonStoreService.setIn(['references'], linkedReferences);

        this.toastrService.clear(infoToast.toastId);
        this.toastrService.success(`References are linked.`, 'Success');
      }).catch(error => {
开发者ID:inspirehep,项目名称:record-editor,代码行数:6,代码来源:link-references-button.component.ts


注:本文中的ng2-json-editor.JsonStoreService.setIn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。