php - 新手问题 - php & mustache 迭代
问题描述
我在迭代一组数据时遇到了困难。我的代码如下:
$root = $_SERVER['DOCUMENT_ROOT'];
require $root.'/assets/js/mustache.php-2.13.0/src/Mustache/Autoloader.php';
include($root."/utilities.php");
Mustache_Autoloader::register();
$url = "http://development.somesite.com/pages/lookup/sql/getData.php?dir=A&process=20&d=O";
$r = json_decode(Insert($url));
$template = "{{{#r}}}<b>{{PropName}}</b></br>{{{/r}}}";
$m = new Mustache_Engine;
$html = $m->render($template, $r);
echo "html: ".$html."</br>";
var_dump($r);
我得到的结果是:
html:
array(317) { [0]=> object(stdClass)#2 (2) { ["PropNo"]=> string(3) "409" ["PropName"]=> string(21) "WRD Avenue LLC" } [1]=> object(stdClass)#3 (2) { ["PropNo"]=> string(3) "410" ["PropName"]=> string(21) "1111 Avenue AB" }...}
该数组是使用 json_decode 创建的。我确信答案很简单,但我显然在这里遗漏了一些东西。
谢谢你的帮助。
解决方案
我得到它的工作如下:
将 $template 更改为:
$template = "{{#r}}<b>{{PropName}}</b></br>{{/r}}";
并将渲染更改为:
$html = $m->render($template, array('r'=>$r));
推荐阅读
- sharepoint - 使用 PowerApps 如何在总共有 20k+ 条记录的 SharePoint 列表中批量更新 1% 到 10% 的记录
- windows - 无法 git checkout master:无效路径“?”
- android - 如何获取发送按键事件的键盘名称?
- azure-sql-database - Azure SQL 超大规模层
- java - 使用 java 扫描仪时如何检查 \n?
- vue.js - 在托管的 Nuxt 应用程序中利用错误布局
- node.js - 为什么应用程序默认部署到使用 HTTP 在移动设备上打开的 heroku?
- php - Symfony 5 Delete方法,无法猜测如何从参数的请求信息中获取Doctrine实例
- django - 在序列化程序中使用不代表模型对象的主键是最佳实践吗?
- c# - Reactive Ui Dynamic Data,ui刷新问题