【问题标题】:How to display images from my API JSON array?如何显示来自我的 API JSON 数组的图像?
【发布时间】:2015-11-17 13:02:43
【问题描述】:

如何显示通过我的 API 接收的 JSON 子数组中的图像? 我可以显示标题、价格和描述,但不能显示实际图像。 谁能给我小费?

我的 XML:

我的 JSON 结构:

【问题讨论】:

  • 您好,您无法将对象数组设置为图像。你需要的是这样的: url_to_your_image.com">
  • 请注意,您应该在问题本身中编写代码 - 强烈不鼓励使用代码截图。

标签: json api titanium titanium-alloy


【解决方案1】:

如果您只需要显示一张图像,请使用dataTransform 属性,您还可以使用dataCollection 属性(请参阅https://appcelerator.github.io/appc-docs/latest/#!/guide/Alloy_Data_Binding-section-36739592_AlloyDataBinding-Collection-ViewBinding)从 JSON 中选择/组合图像 URI,然后使用 @ 中的属性987654324@

【讨论】:

  • 我也这样做了但是它不起作用
  • 这不是我的建议。在 XML 中使用 <ImageView image="{myImage}" />,然后在您拥有 dataCollection 属性的地方,添加一个 dataTransform 属性以传递一个使用模型返回类似“transformed.myImage = changed.images[0].sizes[6]”的函数。有关更多指导,请参阅我之前评论中的链接。
  • 链接断开@FokkeZandbergen
【解决方案2】:

您需要遍历图像数组并在 JS 中创建 ImageView。要显示图像,您可以使用 ScrollableView (http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.ScrollableView) 并将图像添加为视图。

【讨论】:

  • // 我这样做了,但它不起作用 var args = arguments[0] || {}; var collection = Alloy.Collections.ProductCollection; collection.fetch({ 成功 : function(){ _.each(collection.models, function(element, index, list){ element.attributes.images = element.attributes.images[0].sizes['100']; }); }, 错误:function(){ Ti.API.error("hmm - 这不好!"); } });
  • 我不建议走这条路。你想要的正是 dataTransform 的用途。
猜你喜欢
  • 1970-01-01
  • 2022-01-21
  • 1970-01-01
  • 1970-01-01
  • 2013-05-31
  • 1970-01-01
  • 1970-01-01
  • 2022-12-23
  • 1970-01-01
相关资源
最近更新 更多