【问题标题】:Fetching data from external XML with Alloy in Titanium使用钛合金从外部 XML 中获取数据
【发布时间】:2013-01-08 14:51:56
【问题描述】:

我正在开发我的第一个使用 Appcelerator Titanium 制作的 iPhone 应用程序。我正在使用 Alloy 框架。

我只有一般的 JavaScript 背景。我已经阅读了 BackboneJS 的工作原理,但是我正在为这个概念而苦苦挣扎。

这个应用程序非常基础,我只需要获取一个包含 XML 响应的 URL。示例:http://www.domain.com/api.php?listProducts

此 URL 将响应类似这样的内容

<response>
<request>
<timestamp id="0.66266400 1357656226"/>
<status id="100">OK</status>
</request>
<api_function>getproductsimage</api_function>
<products>
<product id="1">
<images>
<image name="featured" width="640" height="347" src="../html/productImages/featured.jpg"/>
<image name="nonretina" width="125" height="95" src="../html/productImages/thumbnail.jpg"/>
<image name="retina" width="250" height="190" src="../html/productImages/thumbnail.jpg"/>
<image name="ldpi" width="" height="" src=""/>
<image name="mdpi" width="" height="" src=""/>
<image name="hdpi" width="" height="" src=""/>
<image name="xhdpi" width="" height="" src=""/>
</images>
</product>
</product>
</products>
</response>

我想在 TableView 中处理这些数据,显然会有不止一个响应。但是,我并不真正了解有关在 BackboneJS 中制作 XHR 的文档。谁能帮我制作一个简单的集合/模型来简单地获取这个 URL 并显示数据。

提前致谢

【问题讨论】:

    标签: backbone.js collections xmlhttprequest titanium appcelerator-mobile


    【解决方案1】:

    这纯粹是一个backbonejs Model parse 问题,因为主干使用 JSON 响应,而您正在查看返回 XML。

    不要求您使用 Alloy 模型来解决此问题,因此您可以使用 http 请求实现您的解决方案并自己填充对象。

    【讨论】:

    • 这是您可能想要使用的 Ti.Network.HTTPClient 的“mrbrandbart”链接:docs.appcelerator.com/titanium/latest/#!/api/…
    • 非常感谢您的反馈。我们改变了我们的 API,从将 XML 结果提供给 JSON。刚刚完成了一些硬编码的 JSON 示例示例,现在将尝试使用它制作模型和集合。非常感谢!
    • 没问题,Alloy 是一个很好的框架,但是了解 BackboneJS 模型和集合的基础知识将大大有助于让您的生活更轻松。以下是我所做的一些工作链接,可能会对您有所帮助clearlyinnovative.com/blog/post/34758523772/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多