velocityjs
Advanced tools
Comparing version 0.9.4 to 0.9.5
@@ -0,1 +1,5 @@ | ||
## 0.9.5 2017-04-07 | ||
- fix: support foreach.hasnext when iterating objects [!81](https://github.com/shepherdwind/velocity.js/pull/81) | ||
## 0.9.4 2017-01-16 | ||
@@ -2,0 +6,0 @@ |
{ | ||
"name": "velocityjs", | ||
"description": "Velocity Template Language(VTL) for JavaScript", | ||
"version": "0.9.4", | ||
"version": "0.9.5", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "velocity template" |
@@ -198,26 +198,39 @@ 'use strict'; | ||
var len = utils.isArray(_from) ? _from.length : utils.keys(_from).length; | ||
if (utils.isArray(_from)) { | ||
var len = _from.length; | ||
utils.forEach(_from, function(val, i) { | ||
if (this._state.break) { | ||
return; | ||
} | ||
// 构造临时变量 | ||
local[_to] = val; | ||
local.foreach = { | ||
count: i + 1, | ||
index: i, | ||
hasNext: i + 1 < len | ||
}; | ||
local.velocityCount = i + 1; | ||
utils.forEach(_from, function(val, i) { | ||
this.local[contextId] = local; | ||
ret += this._render(_block, contextId); | ||
if (this._state.break) { | ||
return; | ||
} | ||
// 构造临时变量 | ||
local[_to] = val; | ||
// TODO: here, the foreach variable give to local, when _from is not an | ||
// array, count and hasNext would be undefined, also i is not the | ||
// index. | ||
local.foreach = { | ||
count: i + 1, | ||
index: i, | ||
hasNext: i + 1 < len | ||
}; | ||
local.velocityCount = i + 1; | ||
}, this); | ||
} else { | ||
var len = utils.keys(_from).length; | ||
utils.forEach(utils.keys(_from), function(key, i) { | ||
if (this._state.break) { | ||
return; | ||
} | ||
local[_to] = _from[key]; | ||
local.foreach = { | ||
count: i + 1, | ||
index: i, | ||
hasNext: i + 1 < len | ||
}; | ||
local.velocityCount = i + 1; | ||
this.local[contextId] = local; | ||
ret += this._render(_block, contextId); | ||
}, this); | ||
} | ||
this.local[contextId] = local; | ||
ret += this._render(_block, contextId); | ||
}, this); | ||
// if foreach items be an empty array, then this code will shift current | ||
@@ -224,0 +237,0 @@ // conditions, but not this._render call, so this will shift parent context |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
404022
2692