【问题标题】:Populating mxml with JSON data containing urls使用包含 url 的 JSON 数据填充 mxml
【发布时间】:2015-07-20 07:59:28
【问题描述】:

我今天刚开始学习 Flex。我遇到了一个问题。我的网络服务返回了一些 JSON 数据,如下所示:

[{"id":"34","url":"im3.png","uid":"1","pr":"1"},{"id":"33","url":"im2.jpg","uid":"1","pr":"0"},{"id":"32","url":"im1.jpg","uid":"1","pr":"1"}]

我可以对其进行解码并存储在填充我的 DataGrid 的数组中。

<mx:DataGrid id="prGallery" left="25" right="25" top="25" bottom="25" dataProvider="{prDB}">

prDB 在“加载时”初始化。

一切正常,但是...我想从这些 URL 中显示图像(图像存储在我的服务器上 xxxxx.xx/url 下。

存储像<img src="xxxxx.xx/url"/> 这样的标签显然是行不通的。所以我的问题来了:

  1. 首先,使用 DataGrid 来显示图像是个好主意吗? (尽管我看不到结果,但我认为不是。)
  2. 我应该使用什么其他组件来填充 未知数量 的记录。 (行包含文本和图像)。

【问题讨论】:

    标签: json actionscript-3 apache-flex datagrid mxml


    【解决方案1】:
    1. 使用 DataGrid 是个好主意吗? - 这实际上取决于图像的大小和您看到的结果。如果你对输出足够满意,你可以很好地使用它。

    2. 对于未知数量的记录,我会说 DataGrid 不是一个糟糕的选择。您可以通过少量使用服务器端代码来限制行数并实现分页。

    但是,我不明白为什么你不能使用<img src="obj.url" />。您没有将 itemRenderer 用于 DataGrid 列吗?如果没有,请考虑。

    例如,

    <mx:DataGrid id="myGrid" height="400" width="600" dataProvider="{jsonData}">
    <mx:columns> <mx:DataGridColumn dataField="id"/> <mx:DataGridColumn dataField="url" itemRenderer="myComponents.ImageRenderer"/> <mx:DataGridColumn dataField="Price"/> </mx:columns>
    </mx:DataGrid>

    您需要创建一个自定义组件ImageRenderer 来显示图像。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-15
      • 1970-01-01
      • 2020-05-12
      • 2018-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多