You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by beyaRecords <uz...@beyarecords.com> on 2005/01/14 13:05:39 UTC
TypeError: getStock is not a function.
Hi,
I'm sure that this is a simple one but it eludes me at the moment. I
have 2 identical operations happening both in a jx page as well as a
validation form:
jx page:
<jx:forEach var="orderitem" items="${neworder.getOrderItems()}">
<tr>
<td class="normaltext">${orderitem.getStock().getItemTitle()}</td>
</tr>
</jx:forEach>
and in my formvalidation.xml:
<fd:javascript>
for (var orderitem in neworder.getOrderItems()){ <---------- This
line is fine.
if (orderitem.getStock().getItemTitle() == "abcd") { <----- This
line is causing the error.
...do something.....
}
}
</fd:javascript>
The code in the jx page works, but the javascript in the xml file gives
the above mentioned error message. What am I missing here?
regards
Uzo
Re: TypeError: getStock is not a function.
Posted by beyaRecords <uz...@beyarecords.com>.
On 14 Jan 2005, at 13:32, Vilya Harvey wrote:
> var orderitems = neworder.getOrderItems();
> for (var i = 0; i < orderitems.size(); i++) {
> var orderitem = orderitems.get(i);
> if (orderitem.getStock().getItemTitle() == "abcd") {
> ... do something.....
> }
> }
Hi,
manages to find a solution guys. The solution is as follows:
orderitems = neworder.getOrderItems().iterator();
while (orderitems.hasNext()) {
orderitem = orderitems.next();
if (orderitem.getStockID() == stock_code){
duplication = true;
}
}
Thanks all for your help.
regards
Uzo
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: TypeError: getStock is not a function.
Posted by Vilya Harvey <vi...@gmail.com>.
beyaRecords wrote:
> <fd:javascript>
> for (var orderitem in neworder.getOrderItems()){ <---------- This line
> is fine.
> if (orderitem.getStock().getItemTitle() == "abcd") { <----- This line
> is causing the error.
> ...do something.....
> }
> }
>
> </fd:javascript>
>
> The code in the jx page works, but the javascript in the xml file
> gives the above mentioned error message. What am I missing here?
In javascript, the for/in loop is for iterating over the properties of
an object, not over a collection. So if the return type of
getOrderItems() is a list, you'll actually be iterating over the
properties of the list, rather than it's contents. If you rewrite the
loop as
var orderitems = neworder.getOrderItems();
for (var i = 0; i < orderitems.size(); i++) {
var orderitem = orderitems.get(i);
if (orderitem.getStock().getItemTitle() == "abcd") {
... do something.....
}
}
then it should work for you.
Vil.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org