È piuttosto banale scrivere codice lato server per elaborare i modelli jQuery.
Questo è il some very basic vb.net code che ho creato per restituire il risultato di una stringa di modello jquery a una matrice di qualsiasi oggetto. Attualmente lo fa solo la sostituzione di dati di valori
Public Shared Function RenderTemplate(template As String, list As Array) As String
Dim myRegexOptions As RegexOptions = RegexOptions.Multiline
Dim myRegex As New Regex(strRegex, myRegexOptions)
Dim splits = myRegex.Split(template)
Dim matches = myRegex.Matches(template)
Dim i As Integer = 0
Dim swap As Boolean = False
Dim str As New StringBuilder
For Each item In list
swap = False
For i = 0 To splits.Length - 1
If swap Then
str.Append(CallByName(item, splits(i), CallType.Get, Nothing))
Else
str.Append(splits(i))
End If
swap = Not swap
Next
Next
Return str.ToString
End Function
Quindi, se ho inviato il seguente ...
Dim strTargetString As String = "<p><a href='${Link}'>${Name}</a></p>"
Dim data As New Generic.List(Of TestClass)
data.Add(New TestClass With {.Link = "http://stackoverflow.com", .Name = "First Object"})
data.Add(New TestClass With {.Link = "http://stackexchange.com", .Name = "Second Object"})
Return Render(strTargetString, data.ToArray)
Sarebbe uscita come una stringa
<p><a href='http://stackoverflow.com'>First Object</a></p>
<p><a href='http://stackexchange.com'>Second Object</a></p>
Questo funziona molto più veloce di generare un falso oggetto browser sul server ed eseguire l'intera libreria jQuery solo per sostituire alcuni tag.
Che cosa è esattamente la tua domanda? (vedi anche [Esiste un motore di template per Node.js?] (http: // StackOverflow.it/questions/1787716/is-there-a-template-engine-per-node-js)) –
Il lato server è più affidabile perché lato client non si conosce le specifiche degli utenti e potrebbe ridurre drasticamente le prestazioni sul lato utente – RobertPitt
Potresti dare un'occhiata al blog @ getify (http://blog.getify.com/) - si lamenta della parità di meccanismi di templating e validazione tra client e server * per tutto il tempo * – Pointy