私のページにはブートストラップに基づいたアーティファクトスライダがあります。私はグローバル変数を定義して(Javaスクリプトで)サーバから返されたアーティファクトの数を数えます。クラス 。 「(k.nodes未定義私のjqueryテンプレート内にグローバル変数を使用することはできません
であると私は私の変数を記録しようとすると:私は(私の場合の場合)jQueryのテンプレートで私の変数を使用していたときにしかし、私は
例外TypeError以下のエラーが取得しますconsole.logでartifactCounterV」)()、変数の値を印刷した後、私はこのエラーが
TypeError例外を取得:プリミティブ型に変換することはできません
は、これは私のhomePage.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>home page</title>
<script language="javascript" type="text/javascript">
var restUrl = "<c:url value = '/rest/core/goods/products/book' />";
var restUrlOrderItem = "<c:url value = '/rest/order/orderItem/front/addToBasket/' />";
var artifactCounterV = 1;
$(function() {
fillTable();
});
function artifactCounter()
{
return artifactCounterV++;
}
function fillTable() {
$('#entityBody' + ' :not(script)').remove();
$.getJSON(restUrl + "/front/list/getAll", function(entities) {
if (entities.entityList)
$('#GridRowTemplate').tmpl(entities.entityList).prependTo(
'#entityBody');
else {
$('#GridRowTemplate').tmpl(entities).prependTo("#entityBody");
}
});
}
function addToShoppingCart(productId) {
$.ajax({
type : "POST",
url : restUrlOrderItem + productId,
success : function(res) {
if (res)
return res.id
}
});
}
function goToBasketPage(){
window.location="<c:url value ='/View/frontEnd/cart/Index.jsp'/>";
}
</script>
</head>
<body>
<span id="confirm"></span>
<%@ include file="Header.jsp"%>
<%@ include file="TopMenu.jsp"%>
<%@ include file="Commercial.jsp"%>
</body>
</html>
と、ここで私のartifactSlider.jsp
artifactSlider.jspはcommercial.jsp内icludedされ、商業のページにはJavaスクリプトコードを、その純粋なHTMLはありません。
<!------------- product-slider ----------->
<div id="carousel-example" class="carousel slide hidden-xs "
data-ride="carousel">
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div id="entityBody" class="entityBody">
<script id="GridRowTemplate" type="text/html">
${console.log(artifactCounterV)}
{{if artifactCounterV == 1 }}
<div class="item active">
<div class="row">
{{/if}}
{{if artifactCounterV==6}}
<div class="item">
<div class="row">
{{/if}}
<div class="col-sm-2 item-holder">
<div class="col-item">
<div class="photo">
<img
src="<c:url value='/rest/attachment/front/getFile/' />${pictureCode}"
class="img-responsive" />
</div>
<div class="info">
<div class="row">
<div class="price col-md-12">
<h5>${name}</h5>
<h5 class="price-text-color separator">
<span>price: </span> ${price} $
</h5>
</div>
</div>
<div class="separator">
<p class="btn btn-default col-md-12">
<i class="fa fa-shopping-cart"></i> <span href=""
class="hidden-sm" onclick="addToShoppingCart(${id})">add to basket</span>
</p>
<p class="btn btn-default col-md-12">
<i class="fa fa-list"></i> <a class="hidden-sm" href="">more</a> <span style="display: none">${artifactCounter()}</span>
</p>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
{{if artifactCounterV==6 || (artifactCounterV>6 && artifactCounterV<=12) }}
</div>
</div>
{{/if}}
</script>
</div>
</div>
</div>
<!------------- product-slider ----------->
は、DOMレンダリング前または後にJSコードが含まれていますか? – Cruiser
は、このライブのどこかでデバッグできますか? –
親愛なる@クルーザー私のコードを編集しました。実際には私のサンプルにあります –