evalDSJsonPath
evalDSJsonPath
Evaluates a JSONPath expression against DataSource data and returns the list of matching values.
Parameters
dmPath(String): The DataSource path to query (e.g."dsName.fieldName")regularPath(String): The JSONPath expression to evaluate (e.g."$[*].price")
Returns: List — the list of values matching the JSONPath expression. Returns an empty array ([]) when nothing matches or the path is invalid.
Description
Evaluates a JSONPath expression against the data bound to a DataSource (DS). Specify a particular field or list of the DataSource with dmPath and a JSONPath expression with regularPath, and every matching item inside that data is extracted and returned.
Unlike $vm.evalProviderJsonPath, which queries a Provider Instance's most recent raw response, evalDSJsonPath queries the data actually bound to the DataSource. This is useful for extracting values based on what is bound to widgets, or for verifying the result after modifying the DS with insertDSValue, appendDSValue, and similar methods.
Write JSONPath expressions relative to the array root ($[*]). Standard JSONPath syntax is supported, including nested field access (.fieldName) and condition filters ([?(@.key == 'value')]).
Example
// DS "stockList"의 전체 항목 중 price 필드 값을 추출
const prices = $vm.evalDSJsonPath("stockList", "$[*].price");
$log.debug("가격 목록: " + JSON.stringify(prices));
// price가 10000 이상인 항목의 name 필드만 추출
const highPriceNames = $vm.evalDSJsonPath("stockList", "$[?(@.price >= 10000)].name");
$log.debug("고가 종목: " + JSON.stringify(highPriceNames));
// 결과가 없을 경우 처리
if (highPriceNames.length === 0) {
$log.debug("조건을 만족하는 항목이 없습니다.");
}
Related
$vm.evalProviderJsonPath(recvPath, regularPath)— evaluate JSONPath against a Provider Instance's response data.$vm.getDSValue(path)— return the value at a given DataSource path.$vm.insertDSValue(recordPath, jsonData)— insert a new record into a DataSource.$vm.appendDSValue(recordPath, jsonData)— append a new record to the end of a DataSource list.