Skip to content

Solve search with parameter single=true and no results#119

Open
estercolero82 wants to merge 1 commit into
hbi99:masterfrom
estercolero82:master
Open

Solve search with parameter single=true and no results#119
estercolero82 wants to merge 1 commit into
hbi99:masterfrom
estercolero82:master

Conversation

@estercolero82

Copy link
Copy Markdown

When doing a defiant.search with the option single=true and no results found throws an exception: xres[i] is null. This commit solves the problem.
Sample code:
(async () => {
// import 'defiant'
var defiant = await fetchScript('/res/js/modules/defiant.js');
var data = {
"car": [
{"id": 10, "color": "silver", "name": "Volvo"},
{"id": 11, "color": "red", "name": "Saab"},
{"id": 12, "color": "red", "name": "Peugeot"},
{"id": 13, "color": "yellow", "name": "Porsche"}
],
"bike": [
{"id": 20, "color": "black", "name": "Cannondale"},
{"id": 21, "color": "red", "name": "Shimano"}
]
};

//Search with 0 results looking for a single node
var search = defiant.search(data, '//car[color="brown"]/name', true);
console.log(search);
})();

When doing a defiant.search with the option single=true and no results found throws an exception: xres[i] is null. This commit solves the problem.
Sample code:
(async () => {
  // import 'defiant'
  var defiant = await fetchScript('/res/js/modules/defiant.js');
  var data = {
      "car": [
          {"id": 10, "color": "silver", "name": "Volvo"},
          {"id": 11, "color": "red",    "name": "Saab"},
          {"id": 12, "color": "red",    "name": "Peugeot"},
          {"id": 13, "color": "yellow", "name": "Porsche"}
      ],
      "bike": [
          {"id": 20, "color": "black", "name": "Cannondale"},
          {"id": 21, "color": "red",   "name": "Shimano"}
      ]
  };
  

 //Search with 0 result looking for a single node
  var search = defiant.search(data, '//car[color="brown"]/name', true);
  console.log(search);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant