/ / Dust.Js Abschnitte und Pfade - json, dust.js

Dust.Js Abschnitte und Pfade - json, dust.js

Ich erhalte einen Fehler JSON im folgenden Format

error = [{field:"one", desc:"This is error for field one", value="FromPostFieldOne"},
{field:"two", desc:"This is error for field two", value="FromPostFieldTwo"}];

welches ich in der folgenden Vorlage anzeigen möchte

{#error}
<form>
<input type="text" name="one" id="one" value="<!- value for field one from JSON-->"/>
<!-- Display error from JSON for field one here -->

<input type="text" name="two" id="two" value="<!- value for field two from JSON -->"/>
<!-- Display error from JSON for field two here -->

</form>
{/error}

Ich kann mir nicht vorstellen, ob ich das mit erreichen kannÄther "Explicit context setting" oder "{@if cond =" Bedingung "} helper". Alle Beispiele auf Linkedin Dust-Site veranschaulichen, wie dies mit JSON-Schlüsselwerten, nicht jedoch mit Objektarrays, durchgeführt wird.

Hilfe geschätzt !!!!

Antworten:

1 für die Antwort № 1

Dein JSON ist nicht gültig, du solltest so etwas machen:

 error = [
{
field:"one",
desc:"This is error for field one",
value:"FromPostFieldOne"
},
{
field:"two",
desc:"This is error for field two",
value:"FromPostFieldTwo"}
];