我刚刚开始使用 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:“描述未定义”。我还尝试在列表项的属性名称之前使用 this 和 InvoiceLine,如下所示,但这也不起作用。
Desc = {{this.Description}} , Cost = {this.Cost}}
Desc = {{InvoiceLine.Description}} , Cost = {InvoiceLine.Cost}}
如何让它发挥作用?
此外,如果列表嵌套在数据内的另一个对象中 - 是否仍然可以访问列表项的属性?
您的模板中似乎存在小错误:
{Cost}}
而不是{{Cost}}
。
应该是
{{#each InvoiceLines}}
Desc = {{Description}} , Cost = {{Cost}}
{{/each}}
你能尝试一下吗?