[英]How can I get Javascript to execute as a table is being built?
I have a table being built in HTML (using ASP), and it's stepping through a recordset. 我有一个用HTML(使用ASP)构建的表,它正在逐步通过记录集。 As it steps through the recordset, it creates a new row for the html table and fills it with data.
当它逐步遍历记录集时,它将为html表创建一个新行,并用数据填充它。
The problem I'm having is that it's using numbers that can be 10 or 11 digits long, and I want to format it with commas. 我遇到的问题是它使用的数字可能是10或11位数字,我想用逗号对其进行格式设置。 I have a formatNumbers function that works excellently.
我有一个出色的formatNumbers函数。 However, basically what I need to do is this:
但是,基本上我需要做的是:
<td><script>formatNumber(<% = RS("total_rolled_lineal_ft")%>,0,0,true);</script></td>
I'm getting an Object Expected error. 我收到“对象期望”错误。 If we take a line from the executed HTML, here's what it looks like:
<td><script>formatNumber(10843537,0,0,true);</script></td>
如果我们从已执行的HTML中提取一行,则外观如下所示:
<td><script>formatNumber(10843537,0,0,true);</script></td>
Any clue what's causing my error, or, if I'm doing it completely wrong, how to fix it? 有什么线索导致我的错误,或者,如果我做错了什么,该如何解决?
Also, formatNumber returns a string, in this case 10,843,537
. 另外,formatNumber返回一个字符串,在这种情况下为
10,843,537
。
Thanks to @nnnnnn, I ended up using VB's FormatNumber() and came up with this 感谢@nnnnnn,我最终使用了VB的FormatNumber()并提出了这个
<% = FormatNumber(RS("total_rolled_lineal_ft"),0,true,true,true)%>
, which works excellently. <% = FormatNumber(RS("total_rolled_lineal_ft"),0,true,true,true)%>
,效果非常好。
I have never used straight ASP so maybe I am missing something in this answer. 我从未使用过纯ASP,因此也许我在此答案中遗漏了一些东西。
Technically you can not execute Javascript while the ui is rendering, browsers tend to be a single threaded affair and will do one thing or the other. 从技术上讲,在ui呈现时您无法执行Javascript,浏览器往往是单线程事务,并且会做一件事或另一件事。
But I would suggest that instead of binding the table directly to a record set you transform the record set into a ViewModel type class in the code behind. 但是我建议不要在后面的代码中将记录集转换为ViewModel类型类,而不是将表直接绑定到记录集。
You would then perform this conversion as you are building your ViewModel. 然后,在构建ViewModel时将执行此转换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.