【问题标题】:Parameter to ArrayData constructor needs to be an object or associative arrayArrayData 构造函数的参数需要是对象或关联数组
【发布时间】:2017-01-12 08:42:05
【问题描述】:

我有以下ArrayList在前端迭代$SuitableRooms下:https://gist.github.com/anonymous/9db25ffe78b14463b7b4392f9da9d7f8

我可以毫无问题地浏览第一个维度的属性,例如。

<% loop $SuitableRooms %>
    $Name <!-- returns "Grande Club Room" for example (correct) -->

    <% loop $Top.SuitableRooms.Attributes %> // I know $Top.SuitableRooms isn't needed, just put this here to emphasise that I know I'm in the right scope
        $Name <br/> <!-- should return "Smokers Allowed" for example but returns "Attributes" -->
    <% end_loop %>
<% end_loop %> 

应该返回:

高级俱乐部间

  • 吸烟者允许
  • 海景

但返回:

高级俱乐部间

  • 属性
  • 属性
  • 属性

所以很明显问题出在我的 ArrayList 的结构上,虽然我无法找出我哪里出错了。

【问题讨论】:

  • 在您的代码中,您调用的是&lt;% loop $Top.SuitableRooms.Attributes %&gt; 还是&lt;% loop $Attributes %&gt;
  • 在所提供的上下文中,任何一个都是正确的,并且两者都可以工作@3dgoo - 找到我的问题并发布它

标签: templates silverstripe


【解决方案1】:

在“关联数组”的定义中,我的回答很明显是“在我面前”

ArrayData::create(
    array(
        array(
            "Im not accessible"
        )
    )
)

对比

ArrayData::create(
    array(
        "Items" => array(
            "I am now accessible"
        )
    )
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-25
    • 1970-01-01
    • 1970-01-01
    • 2012-11-11
    • 1970-01-01
    • 2012-04-17
    相关资源
    最近更新 更多