带有.CSV项目/对象的动态.HTML

jtw3ybtb  于 2023-04-03  发布在  其他
关注(0)|答案(1)|浏览(85)

而不是创建30多个不同的网页,我想创建一个网页,将拉到与用户将期望相应的信息页面的csv项目。
有没有服务器端的一部分,这一点。我希望管理员改变网站的源代码,以适当的CSV为每一个赛季,他们举办的活动,使这不是一个问题
CSV File WITH GRID VIEW - for simplicity

id,Session_Leader_first_Name,Session_Leader_last_Name,email,room_Number,session_Name,start-time,date
1,Ollie,Mathias,omathias0@exblog.jp,11,"Murazik, Kuhn and Quigley",4:14 PM,7/30/2022
2,Elie,Dennington,edennington1@free.fr,21,Hintz-Stroman,5:51 PM,10/3/2022
3,Gregorio,Smiz,gsmiz2@admin.ch,3,"Kulas, Veum and Rolfson",4:08 PM,8/29/2022
4,Caryl,Creese,ccreese3@unblog.fr,41,"Muller, Little and Lesch",5:15 PM,1/1/2023
5,Manuel,Hartopp,mhartopp4@usatoday.com,21,Cummings Group,5:59 PM,9/4/2022
6,Baudoin,Dennis,bdennis5@adobe.com,11,Parker-Parker,5:44 PM,5/13/2022
7,Franz,Earl,fearl6@twitter.com,11,Vandervort and Sons,5:47 PM,5/1/2022
8,Nani,Shakelady,nshakelady7@imageshack.us,30,"Russel, Dickens and Kuhn",4:35 PM,7/19/2022
9,Phil,Stoaks,pstoaks8@accuweather.com,21,MacGyver-Kub,5:16 PM,1/29/2023
10,Maryjane,Iacovazzi,miacovazzi9@addtoany.com,21,"McDermott, Kling and Bashirian",5:01 PM,11/1/2022
11,Siouxie,Sowden,ssowdena@fastcompany.com,12,Heidenreich and Sons,4:43 PM,7/28/2022
12,Carny,Treffry,ctreffryb@clickbank.net,11,Runte Inc,3:48 PM,8/12/2022
13,Stephan,Lindgren,slindgrenc@jigsy.com,20,Flatley Group,4:35 PM,3/12/2023
14,Linda,Caron,lcarond@blogspot.com,31,Watsica LLC,3:46 PM,9/24/2022
15,Kip,Lilburn,klilburne@google.pl,40,Will-Schmitt,5:07 PM,7/7/2022

使用此文件,我需要使用标识符(id)从主页面生成一个网页的信息与相应的信息
我找不到任何地方有任何信息如何做到这一点在一个consistant的方式.我希望我的网站使用JavaScript来取代文本中的HTML文件与正确的信息,以什么用户将期望基于以前的id,他们点击(E.x从索引页).
我试过用Jquery来帮助JavaScript解释信息,但我没有运气把信息打印到页面上。
HTML的一个示例如下:

<HTML>

  <div> Welcome to information!

    <div> Your Session Leader for [id] is [id.Session_Leader_first_Name]

这是一个非常粗糙的例子,但正是我的目标是解决。

3xiyfsfu

3xiyfsfu1#

我有一个工具,大致可以满足你的需求,不幸的是我的工具是用powershell编写的,我把它作为一个答案,希望你或其他人可以用javascript重新实现它。
Expand-csv遍历csv文件,并将数据作为实际值插入模板中的变量数据。这会产生一系列基本形式相同但内容不同的扩展。
对于您的示例,csv文件看起来与您提供的文件类似:

id,Session_Leader_first_Name,Session_Leader_last_Name,email,room_Number,session_Name,start-time,date
1,Ollie,Mathias,omathias0@exblog.jp,11,"Murazik, Kuhn and Quigley",4:14 PM,7/30/2022
2,Elie,Dennington,edennington1@free.fr,21,Hintz-Stroman,5:51 PM,10/3/2022
3,Gregorio,Smiz,gsmiz2@admin.ch,3,"Kulas, Veum and Rolfson",4:08 PM,8/29/2022
4,Caryl,Creese,ccreese3@unblog.fr,41,"Muller, Little and Lesch",5:15 PM,1/1/2023
5,Manuel,Hartopp,mhartopp4@usatoday.com,21,Cummings Group,5:59 PM,9/4/2022
6,Baudoin,Dennis,bdennis5@adobe.com,11,Parker-Parker,5:44 PM,5/13/2022
7,Franz,Earl,fearl6@twitter.com,11,Vandervort and Sons,5:47 PM,5/1/2022
8,Nani,Shakelady,nshakelady7@imageshack.us,30,"Russel, Dickens and Kuhn",4:35 PM,7/19/2022
9,Phil,Stoaks,pstoaks8@accuweather.com,21,MacGyver-Kub,5:16 PM,1/29/2023
10,Maryjane,Iacovazzi,miacovazzi9@addtoany.com,21,"McDermott, Kling and Bashirian",5:01 PM,11/1/2022
11,Siouxie,Sowden,ssowdena@fastcompany.com,12,Heidenreich and Sons,4:43 PM,7/28/2022
12,Carny,Treffry,ctreffryb@clickbank.net,11,Runte Inc,3:48 PM,8/12/2022
13,Stephan,Lindgren,slindgrenc@jigsy.com,20,Flatley Group,4:35 PM,3/12/2023
14,Linda,Caron,lcarond@blogspot.com,31,Watsica LLC,3:46 PM,9/24/2022
15,Kip,Lilburn,klilburne@google.pl,40,Will-Schmitt,5:07 PM,7/7/2022

模板文件如下所示:

<br>Welcome to information! Your Session Leader for $id<tab> is $Session_Leader_first_Name<br>

以下命令将使用这些输入运行Expand-csv,并将输出存储在文件中。

Expand-Csv myfile.csv format.tmplt  > result.html

结果会是这样的:

<br>Welcome to information! Your Session Leader for 1<tab> is Ollie<br>
<br>Welcome to information! Your Session Leader for 2<tab> is Elie<br>
<br>Welcome to information! Your Session Leader for 3<tab> is Gregorio<br>
<br>Welcome to information! Your Session Leader for 4<tab> is Caryl<br>
<br>Welcome to information! Your Session Leader for 5<tab> is Manuel<br>
<br>Welcome to information! Your Session Leader for 6<tab> is Baudoin<br>
<br>Welcome to information! Your Session Leader for 7<tab> is Franz<br>
<br>Welcome to information! Your Session Leader for 8<tab> is Nani<br>
<br>Welcome to information! Your Session Leader for 9<tab> is Phil<br>
<br>Welcome to information! Your Session Leader for 10<tab> is Maryjane<br>
<br>Welcome to information! Your Session Leader for 11<tab> is Siouxie<br>
<br>Welcome to information! Your Session Leader for 12<tab> is Carny<br>
<br>Welcome to information! Your Session Leader for 13<tab> is Stephan<br>
<br>Welcome to information! Your Session Leader for 14<tab> is Linda<br>
<br>Welcome to information! Your Session Leader for 15<tab> is Kip<br>

模板中有两个变量,$id和$Session_Leader_first_Name。美元符号使它们看起来像powershell变量。名称对应于csv文件中的两个字段。我添加了一些HTML标记,只是为了显示它们在结果中通过。
最后是Expand-Csv:

<#
.NOTES
    Script: Expand-Csv    Rev:  3.2
    Author: DGC           Date: 2-21-19
.SYNOPSIS
    Generates multiple expansions of a template,
    driven by data in a CSV file.
.DESCRIPTION
    This function is a table driven template tool. 

    It generates output from a template and
    a driver table.  The template file contains plain
    text and embedded variables.  The driver table 
    (in a csv file) has one column for each variable, 
    and one row for each expansion to be generated.
#>
function Expand-csv {
    [CmdletBinding()]
    Param (
       [Parameter(Mandatory=$true)] [string] $driver,
       [Parameter(Mandatory=$true)] [string] $template
    )
    Process {
       Import-Csv $driver | % {
           $_.psobject.properties | % {Set-variable -name $_.name -value $_.value}
           Get-Content $template | % {$ExecutionContext.InvokeCommand.ExpandString($_)} 
       }
    }
}

相关问题