1

在此应用程序中,我需要的 JSON 返回的嵌套结果之一是如下所示的字符串:

"<Money amount="25" currencyCode=""/>"

我将如何提取金额以显示在模型/集合中?

谢谢!

4

1 回答 1

1

Backbone 提供了一个 parse 方法,如果当时提供该方法来获取 http://backbonejs.org/#Model-parse

因此在您的模型定义中将 xml 转换为 json 并将 json 值设置为模型

 var Amodel = Bakcobone.Model.extend({
     parse : function (response) {
         // here you parse your xml and once is converted to json you can set the values to the model
         return parsed response.
     }

 });

要将 xml 解析为 json,请查看以下问题。 使用 Javascript 将 XML 转换为 JSON(并返回)

于 2013-06-17T17:51:10.973 回答