Created
April 9, 2013 00:16
-
-
Save ponych/5341812 to your computer and use it in GitHub Desktop.
loops
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @var $_ index_ACTION | |
*/ | |
//var_dump( $_->_r ); | |
//var_dump( $_->_ss ); | |
echo '_userme:'; | |
var_dump( $this->_userme ); | |
echo session_id(); | |
?> | |
<table> | |
<tbody id="select-factor"> | |
<tr id="dim-color"> | |
<td><input class="dim" type="checkbox" value="red" name="color" />红</td> | |
<td><input class="dim" type="checkbox" value="green" name="color" />绿</td> | |
<td><input class="dim" type="checkbox" value="grey" name="color" />灰</td> | |
<td><input class="dim" type="checkbox" value="black" name="color" />黑</td> | |
</tr> | |
<tr id="dim-shape"> | |
<td><input class="dim" type="checkbox" value="seq" name="shape" />方</td> | |
<td><input class="dim" type="checkbox" value="circle" name="shape" />圆</td> | |
<td><input class="dim" type="checkbox" value="star" name="shape" />星</td> | |
<td><input class="dim" type="checkbox" value="triangle" name="shape" />三角</td> | |
</tr> | |
<tr id="dim-size"> | |
<td><input class="dim" type="checkbox" value="33" name="size" />33</td> | |
<td><input class="dim" type="checkbox" value="34" name="size" />34</td> | |
<td><input class="dim" type="checkbox" value="35" name="size" />35</td> | |
</tr> | |
</tbody> | |
</table> | |
<div id="result"> | |
<table> | |
<thead> | |
<tr> | |
<td>slug</td> | |
<td>Name</td> | |
<td>Number</td> | |
</tr> | |
</thead> | |
<tbody></tbody> | |
</table> | |
</div> | |
<script type="text/javascript"> | |
//<![CDADA[[ | |
function isEmpty(obj) { | |
var isE = true; | |
for (var i in obj) { | |
isE = false; | |
break; | |
} | |
return isE; | |
} | |
function count(obj) { | |
var c = 0; | |
for (var i in obj) { | |
c++; | |
} | |
return c; | |
} | |
var t = {}; | |
$(document).ready(function(){ | |
var rtbody = $('#result table tbody'); | |
$('#select-factor input[type=checkbox]').click(function(){ | |
var r = {}, resultSize = 1; | |
$('#select-factor tr').each(function(){ | |
var tr = this,$this = $(this),$hash = {}; | |
log($this.find('input:checked').length); | |
log($this); | |
$this.find('input:checked').each(function(){ | |
$hash[this.value] = $(this).parent().text(); | |
}); | |
if (!isEmpty($hash)) { | |
r[tr.id.split('-')[1]] = $hash; | |
resultSize = resultSize * count($hash); | |
} | |
}); | |
log(r); | |
log('resultSize:'); | |
log(resultSize,'resultSize'); | |
var result = new Array(resultSize) ,outLoop = 0,outLoopSize = count(r); | |
for (var d in r) { | |
var dim = r[d], innerLoop = 0, loopSize = count(dim); | |
for (key in dim) { | |
log('inner'); | |
log(innerLoop); | |
for (var n = innerLoop; n < resultSize;n=n+loopSize) { | |
log('n');log(n); | |
if (!result[n]) { | |
result[n] = []; | |
} | |
result[n].push(dim[key]); | |
} | |
innerLoop++; | |
} | |
outLoop++; | |
} | |
t = r; | |
log("result:"); | |
log(result); | |
}); | |
}); | |
//]]> | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment