本文整理匯總了TypeScript中ng2-json-editor.JsonStoreService.getIn方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript JsonStoreService.getIn方法的具體用法?TypeScript JsonStoreService.getIn怎麽用?TypeScript JsonStoreService.getIn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ng2-json-editor.JsonStoreService
的用法示例。
在下文中一共展示了JsonStoreService.getIn方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: 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);
}
示例2: onLinkButtonClick
onLinkButtonClick() {
let infoToast = this.toastrService.info('Linking references...', 'Loading', HOVER_TO_DISMISS_INDEFINITE_TOAST);
const references = this.jsonStoreService.getIn(['references']);
this.apiService.getLinkedReferences(references)
.then(linkedReferences => {
this.jsonStoreService.setIn(['references'], linkedReferences);
this.toastrService.clear(infoToast.toastId);
this.toastrService.success(`References are linked.`, 'Success');
}).catch(error => {
this.toastrService.clear(infoToast.toastId);
this.toastrService.error('Could not link references', 'Error');
});
}