gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 11:06:53 26 4
gpt4 key购买 nike

我有一个使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com