mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Fixed support for using native for loops
This commit is contained in:
parent
df86ec83ae
commit
2ac6d56a8e
@ -44,7 +44,7 @@ function parseForEach(value) {
|
|||||||
'in': match[2]
|
'in': match[2]
|
||||||
};
|
};
|
||||||
} else if ((match = value.match(forEachPropRegEx))) {
|
} else if ((match = value.match(forEachPropRegEx))) {
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'nameVar': match[1],
|
'nameVar': match[1],
|
||||||
@ -103,9 +103,9 @@ function parseForEach(value) {
|
|||||||
step = -1;
|
step = -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
step = 1;
|
step = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -146,8 +146,8 @@ ForNode.prototype = {
|
|||||||
|
|
||||||
if (parts.hasOwnProperty('from')) {
|
if (parts.hasOwnProperty('from')) {
|
||||||
// This is a range loop
|
// This is a range loop
|
||||||
|
|
||||||
|
|
||||||
var nameVar = parts.nameVar;
|
var nameVar = parts.nameVar;
|
||||||
var from = parts.from;
|
var from = parts.from;
|
||||||
var to = parts.to;
|
var to = parts.to;
|
||||||
@ -234,7 +234,9 @@ ForNode.prototype = {
|
|||||||
}
|
}
|
||||||
}, this).line('});');
|
}, this).line('});');
|
||||||
} else {
|
} else {
|
||||||
if (this.getProperty('forLoop') === true) {
|
var forLoopProp = this.getProperty('forLoop');
|
||||||
|
|
||||||
|
if (forLoopProp && forLoopProp.toString() === 'true') {
|
||||||
forEachParams = [
|
forEachParams = [
|
||||||
'__array',
|
'__array',
|
||||||
'__index',
|
'__index',
|
||||||
|
|||||||
@ -159,6 +159,10 @@ describe('marko/marko' , function() {
|
|||||||
testRender("test-project/html-templates/looping.marko", {}, done);
|
testRender("test-project/html-templates/looping.marko", {}, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it.only("should allow for looping (native for-loop)", function(done) {
|
||||||
|
testRender("test-project/html-templates/looping-native-for-loop.marko", {}, done);
|
||||||
|
});
|
||||||
|
|
||||||
it("should allow for looping over properties", function(done) {
|
it("should allow for looping over properties", function(done) {
|
||||||
testRender("test-project/html-templates/looping-props.marko", {}, done);
|
testRender("test-project/html-templates/looping-props.marko", {}, done);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -0,0 +1,6 @@
|
|||||||
|
<for each="item in ['a', 'b', 'c']" for-loop="true">
|
||||||
|
${item}
|
||||||
|
</for>
|
||||||
|
<div for="item in ['red', 'green', 'blue']; for-loop=true" >
|
||||||
|
${item}
|
||||||
|
</div>
|
||||||
@ -0,0 +1 @@
|
|||||||
|
abc<div>red</div><div>green</div><div>blue</div>
|
||||||
Loading…
x
Reference in New Issue
Block a user