我一直在教自己JMustache,我正在尝试将地图列表发送到子模板。我有以下Java测试:
class ViewController: UIViewController {
var searchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
searchController.delegate = self
searchController.searchBar.delegate = self
searchController.searchBar.showsBookmarkButton = true
searchController.searchBar.setImage(UIImage(named: "myImage"), for: .bookmark, state: .normal)
}
}
extension ViewController: UISearchBarDelegate {
func searchBarBookmarkButtonClicked(_ searchBar: UISearchBar) {
print("click")
}
}
... complex-partial.htmm :
@Test
public void testWithNestedPartial() {
final WeakHashMap<String, Object> parameters = new WeakHashMap<>();
parameters.put("start", "hello");
final List<Map<String, String>> subParameterList = new ArrayList<>();
WeakHashMap<String, String> subParameters = new WeakHashMap<>();
subParameters.put("greek", "alpha");
subParameters.put("numeric", "1");
subParameterList.add(subParameters);
subParameters = new WeakHashMap<>();
subParameters.put("greek", "beta");
subParameters.put("numeric", "2");
subParameterList.add(subParameters);
parameters.put("sub", subParameters);
final Compiler subTemplateLoadingCompiler = Mustache.compiler()
.withLoader(templateName -> Files.newBufferedReader(Paths.get(TEST_TEMPLATE_PATH + templateName + ".htmm")));
final Template template = subTemplateLoadingCompiler.compile("{{start}}\r\n{{> complex-partial}}");
final String result = template.execute(parameters);
Assert.assertEquals(result, "hello\r\n• alpha\r\n• 1\r\n• beta\r\n• 2\r\n");
}
......结果如下:
{{# sub.this}}
• {{greek}}
• {{numeric}}
{{/ sub.this}}
如果我切换它并将“alpha”和1最后一个,则显示“alpha”和1。
我知道我没有正确编写子模板,并且我尝试了不同的方法来设置其中的参数,但解决方案让我感到厌烦。如何编写此部分以通过此测试?
答案 0 :(得分:1)
他打算使用
parameters.put("sub", subParameterList)
而不是
parameters.put("sub", subParameters)