Skip to content

Commit

Permalink
fix direct access in a nested array {d.array[i].nestedArray[i=0].id}
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrelaud committed Aug 10, 2020
1 parent be00f84 commit 01b3dbd
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### v2.0.2
- Fix locales de-ch and pt-br
- Fix direct access in a nested array `{d.array[i].nestedArray[i=0].id}`

### v2.0.1
- Release July 8th, 2020
Expand Down
1 change: 1 addition & 0 deletions lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ var builder = {
var _conditionToFindObject = _dynamicData[_objName].conditions || [];
var _objNameTemp = _objName+'_temp';

_code.add('prev', 'main', _getSafeVar(_objName) + '={};\n');
_code.add('prev', 'main', 'var '+_arrayOfObjectNameG+'_length = ('+_arrayOfObjectNameG+' instanceof Array)?'+_arrayOfObjectNameG+'.length : 0;\n');
_code.add('prev', 'main', 'for (var '+_arrayOfObjectIndexNameG+' = 0; '+_arrayOfObjectIndexNameG+' < '+_arrayOfObjectNameG+'_length ; '+_arrayOfObjectIndexNameG+'++) {\n');
_code.add('prev', 'main', ' var '+_getSafeVar(_objNameTemp)+' = '+_arrayOfObjectNameG+'['+_arrayOfObjectIndexNameG+'];\n');
Expand Down
38 changes: 38 additions & 0 deletions test/test.builder.buildXML.js
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,44 @@ describe('builder.buildXML', function () {
done();
}
});
it('should direct access to a property in a loop inside a table', function (done) {
var _xml = ''
+ '<table>'
+ ' <tr>'
+ ' {d.modules[i].id} : {d.modules[i].observations[i=0].url}'
+ ' </tr>'
+ ' <tr>'
+ ' {d.modules[i+1].id}'
+ ' </tr>'
+ '</table>';

var _res = ''
+ '<table>'
+ ' <tr>'
+ ' 1 : '
+ ' </tr>'
+ ' <tr>'
+ ' 2 : foo'
+ ' </tr>'
+ ' <tr>'
+ ' 3 : '
+ ' </tr> '
+ '</table>';
var _data = {
modules : [
{ id : '1' },
{
id : '2',
observations : [ { url : 'foo' } ],
},
{ id : '3' }
]
};
builder.buildXML(_xml, _data, function (err, _xmlBuilt) {
helper.assert(_xmlBuilt, _res);
done();
});
});
it('should accept to increment two nested arrays in the same time. Thus, the nested array is flattened', function (done) {
var _xml =
'<xml>'
Expand Down

0 comments on commit 01b3dbd

Please sign in to comment.