尝试迭代并从以下对象获取键/值值:
var schedules = {
"0": {
"STAGE1": "1/2/13",
"STAGE2": "2/12/13"
},
"1": {
"STAGE1": "2/4/13",
"STAGE2": "3/9/13"
}
"2": {
"STAGE1": "4/13/13",
"STAGE2": "5/21/13"
}
}
Run Code Online (Sandbox Code Playgroud)
使用以下jQuery:
$.each(schedules, function(index) {
$.each(schedules[index], function(key, value) {
$("ul#list").append("<li>" + key + " " + value + "</li>");
});
});
Run Code Online (Sandbox Code Playgroud)
所以我最终得到一个简单的列表:
我似乎没有正确使用$ .each()...我做错了什么?谢谢!
我试图在将 SVG 元素转换为 Matrix 后放大它,但是当我开始初始缩放时,SVG 的位置重置为 0,0。我希望缩放和平移从页面加载时移动的位置开始。
<svg id="#svg">
<g id="#mainGrid>
....a bunch of SVG
</g>
<svg>
<script>
var winCenterV = $(window).height()/2;
var winCenterH = $(window).width()/2;
//set mainGrid to the center of window using snap.svg
var mainGrid = Snap.select("#mainGrid");
var myMatrix = new Snap.Matrix();
myMatrix.scale(1,1);
myMatrix.translate(winCenterH,winCenterV);
myMatrix.rotate(0);
mainGrid.transform(myMatrix);
//d3 zoom
var svgElement = d3.select("svg");
var gridELement = d3.select("#mainGrid");
svgElement.call(d3.zoom()
.scaleExtent([1 / 2, 4])
.on("zoom", zoomed));
function zoomed() {
gridELement.attr("transform", d3.event.transform);
}
</script>
Run Code Online (Sandbox Code Playgroud)
“mainGrid”SVG 元素可以很好地缩放和平移,但在第一次缩放鼠标单击或滚轮滚动期间,它会回到它的 0,0 位置(浏览器的左上角),而不是从 myMatrix 设置的转换位置进行缩放和平移。我怎样才能让 d3.event.transform 从这个偏移量开始缩放?