please execute the following code. I can not get the value 'A' from ${$item.abcd[getI()]} ! Even though getI() is 0 ! It seems it is a tmpl bug ! Jquey tmpl plugin is urgly! For some reason I have to try to use it! Jtemplate is better !
If you know the answer please give me an email to jiangdy@jhcc.co.jp Thanks !
----------------------------------------------code-------------------------------------------------
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>未命名頁面</title>
<script type="text/javascript" src="js/jquery-1.5.1.js"></script>
<script type="text/javascript" src="js/jquery-jtemplates.js"></script>
<script type="text/javascript" src="js/jquery.tmpl.js"></script>
<script type="text/javascript" src="js/jquery.tmplPlus.js"></script>
<script>
var jj = 0;
var fs = true;
$(document).ready(function(){
function renderTemplate(container, template, data) {
$(container).empty();
$(template).tmpl(data).appendTo(container);
}
$( "#tmplPeople" ).tmpl( people,
{
key: jj,
abcd: ['A','B','C','D']
}
).appendTo( "#testTmpl" );
});
var people = [
{
firstName: "John",
lastName: "Resig",
options: [ "a", "b", "c" , "d"],
question: [ "a", "e", "f" , "b", "t", "y" , "c" ]
}
];
function getQuesLen() {
return this.data.question.length;
}
function getOptsLen() {
return this.data.options.length;
}
function getI() {
if (fs == false) {
jj += 1;
if (jj > 3) {
jj = 0;
return jj;
}
return jj;
}
if (fs) {
fs = false;
return jj;
}
}
Array.prototype.contains = function (element) {
for (var i = 0; i < this.length; i++) {
if (this[i] == element) {
return true;
}
}
return false;
}
</script>
<style>
#gaicTmplUl { list-style:none; }
#gaicTmplUl li { float:left; display:inline; padding-right:5px; }
</style>
</head>
<body>
<div id="testTmpl"></div>
<script id="tmplPeople" type="text/x-jquery-tmpl">
<div>
<span>${getQuesLen()}</span>--<span>${getOptsLen()}</span>
<div>
<ul id='gaicTmplUl'>
{{each question}}
{{if options.contains(question[$index])}}
<li><a id='opt-${$index}' href='#'>${question[$index]}</a>----${$item.abcd[getI()]}----${getI()}----${jj}</li>
{{else}}
<li>${question[$index]}</li>
{{/if}}
{{/each}}
</ul>
</div>
</div>
</script>
</body>
</html>