c# - 如何在 C# 应用程序中将 Partials 与 Nustache 一起使用?

标签 c# mustache

我有一个使用 Nustache 的 Windows 应用程序。我可以使用 Nustache 迭代对象或数组,但是如何使用 Nustache 进行部分枚举?

Check this link

检查样本 11。

var data = { depts: [
{   name: "Engineering",
    employees: [
        {firstName: "Christophe", lastName: "Coenraets"},
        {firstName: "John", lastName: "Smith"}]
},
{   name: "Sales",
    employees: [
        {firstName: "Paula", lastName: "Taylor"},
        {firstName: "Lisa", lastName: "Jones"}]
}]     };

 var tpl = "{{#depts}}<h1>{{name}}</h1>" +
          "<ul>{{#employees}}{{>employee}}{{/employees}}</ul>{{/depts}}";

var partials = {employee:"<li>{{firstName}} {{lastName}}</li>"};
var html = Mustache.to_html(tpl, data, partials);
$('#sampleArea').html(html);

如何在 C# 中实现相同的功能?

最佳答案

如下图修改tpl!

var tpl = "{{employee}}<li>{{firstName}} {{lastName}}</li>{{/employee}}{{#depts}}<h1>{{name}}</h1>" +
      "<ul>{{#employees}}{{>employee}}{{/employees}}</ul>{{/depts}}";

然后传递你的对象数组。它会正确获取。!!!

关于c# - 如何在 C# 应用程序中将 Partials 与 Nustache 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15542759/

相关文章:

javascript - Mustache.js lambdas 和数字格式化 toFixed

javascript - 如何为 Hogan.js 创建自定义绑定(bind)语法(非转义 HTML 版本)

clojure - 如何在 Mustache 模板引擎中实现自省(introspection)?

javascript - 将客户端模板与主布局分开的好方法

javascript - mustache 条件和循环

c# - EF 6 代码首先将 IEnumerable<> 转换为 Json "Self referencing loop detected with type..."

c# - 将排序列添加到列表 C#

c# - .NET 4.8 Web api 迁移到 .net 6 时出现错误枚举值的问题

c# - 列表的默认容量

c# - 面板 C# 中文本框的存在性检查问题 - Windows 窗体应用程序