簡體   English   中英

新手問題 - php 和小胡子迭代

[英]Newbie Question - php & mustache iteration

我在迭代一組數據時遇到了困難。 我的代碼如下:

$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)); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM