使用Alloy in Titanium从外部XML获取数据

时间:2013-01-08 14:51:57

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

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

我只有一般的JavaScript背景。我已经了解了BackboneJS的工作原理,但我正在努力解决这个问题。

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

此网址将响应此类

<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并显示数据。

提前致谢

1 个答案:

答案 0 :(得分:1)

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

您无需使用Alloy模型来解决此问题,因此您只需使用http请求实现解决方案并自行填充对象。