我正在使用mbostock真棒d3进行简单的html渲染,这是我能想到的最简单的方法,选择一个空div并用HTML填充它.
d3.select($('#thediv')[0])
.selectAll('p')
.data(l).enter()
.append('p')
.html(function(d){return 'd3 ' + d;});
Run Code Online (Sandbox Code Playgroud)
在Win7 Chrome中,我注意到,对于大型数据集,这似乎非常慢.(20000件3.5秒)
这个例子呈现了一个非常简单(虽然很长)的列表:http://jsfiddle.net/truher/NQaVM/
我试过两个解决方案,可见性切换:
$('#thediv').toggle()
Run Code Online (Sandbox Code Playgroud)
并写入一个独立元素:
var p = $('<div>')
d3.select(p[0])...
$('#theparent').append(p)
Run Code Online (Sandbox Code Playgroud)
结果如下:
Firefox:统一快速(600-700毫秒)
Chrome:切换或分离速度很快(800毫秒),否则很慢(3.5秒)
Internet Explorer:分离更快但仍然很慢(1.8秒),否则非常慢(3.2秒)
我的问题是:有更好的解决方案吗?
有了D3,我发现自己做了很多这样的事情:
selectAll('foo').data(['foo']).enter().append('foo')
Run Code Online (Sandbox Code Playgroud)
我想简单地添加一个节点(如果它还不存在),因为我需要在DOM树中的不同位置进行更新,而且我方便的数据并不完全与DOM平行.
这是一个标志,我应该重新构建我的数据,以便它是平行的,还是有一个不那么愚蠢的模式,人们用这种"创造如果失踪"的东西?
我正在尝试设置两个不同的静态资产路由,第二个失败.我错过了什么?
要复制此问题:
从scala样本开始的hello world.
在路由中添加一行,所以现在有两条静态路由:
GET /assets/*file controllers.Assets.at(path="/public", file)
GET /assets2/*file controllers.Assets.at(path="/public2", file)
Run Code Online (Sandbox Code Playgroud)注释掉main.scala.html中的Assets引用,因此它不会抱怨它们
把文件放在公共场所和公共场所2.
$ cat > public/foo.txt
hi
$ mkdir public2
$ cp public/foo.txt public2
Run Code Online (Sandbox Code Playgroud)验证公共目录是否有效.
$ telnet localhost 9000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /assets/foo.txt HTTP/1.0
HTTP/1.1 200 OK
Content-Length: 3
Content-Type: text/plain
Etag: 5246040afe91a4cc93bd838a4d5db3984b99470b
Cache-Control: no-cache
hi
Connection closed by foreign host.
Run Code Online (Sandbox Code Playgroud)验证第二个不起作用.
$ telnet localhost 9000
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /assets2/foo.txt HTTP/1.0
HTTP/1.1 404 …Run Code Online (Sandbox Code Playgroud)