当它们匹配正则表达式(例如**myVar**)时,我需要查找和替换对象中的值;我需要循环的对象是用户定义的,结构各不相同。
这是一个示例对象,为简单起见进行了缩短。
var testObject = {
name: "/pricing-setups/{folderId}",
method: "POST",
endpoint: "/pricing-setups/:folderId",
functionName: "create",
Consumes: null,
filename: "apicontracts/pricingsetups/PricingSetupServiceProxy.java",
pathParam: [
{$$hashKey: "06S",
key: "folderId",
value: "**myVar**"}
],
queryParam: [],
request_payload: "{'title':'EnterAname'}",
returnList: []
}
Run Code Online (Sandbox Code Playgroud)
这个对象被传递到一个主函数中,该函数使用传入的对象构建一个 angularjs 资源对象。
这是我正在使用的结构:
function getTestResult(dataSource, options) {
//input into the service should be api obj and selected environment obj
//extend the passed object with options if passed
var opts = $.extend({}, dataSource, options);
//swap the {param} syntax for :param in opts.endpoint
opts.endpoint = opts.endpoint.replace(/\}/g, "").replace(/\{/g, …Run Code Online (Sandbox Code Playgroud)