Handlebars.Net 迭代列表 [HandlebarsUndefinedBindingException]

问题描述 投票:0回答:1

我刚刚开始使用 Handlebars.Net。我有一个模板包含:

{{#each InvoiceLines}}
   Desc = {{Description}} , Cost = {Cost}}
{{/each}}

我的数据对象如下:

public class Data
{
    public bool IsRenewalInvoice { get; set; }
    public List<InvoiceLine> InvoiceLines { get; set; } 
}

public class InvoiceLine
{
    public string Description { get; set; }
    public string Cost { get; set; }
}

但是,我收到了 HandlebarsUndefinedBindingException:“描述未定义”。我还尝试在列表项的属性名称之前使用 thisInvoiceLine,如下所示,但这也不起作用。

Desc = {{this.Description}} , Cost = {this.Cost}}
Desc = {{InvoiceLine.Description}} , Cost = {InvoiceLine.Cost}}

如何让它发挥作用?

此外,如果列表嵌套在数据内的另一个对象中 - 是否仍然可以访问列表项的属性?

c# .net handlebars.js handlebars.net
1个回答
0
投票

您的模板中似乎存在小错误:

{Cost}}
而不是
{{Cost}}

应该是

{{#each InvoiceLines}}
   Desc = {{Description}} , Cost = {{Cost}}
{{/each}}

你能尝试一下吗?

© www.soinside.com 2019 - 2024. All rights reserved.