我有这个模型
var Item = Backbone.Model.extend({
url: 'http://localhost/InterprisePOS/Product/loaditembycategory/Event Materials'
});
var onSuccess = function(){ alert("success"); };
同时,还有一个集合
var Items = Backbone.Collection.extend({
model: Item
});
以下是我的其余代码:
var item = new Item();
var items = new Items();
item.fetch({ success: onSuccess });
alert(items.get("ItemCode"));
我想要的是简单地获取模型的属性。现在我在firebug上看到了这个。当我在浏览器上运行它时,我会得到警告成功,下一个警告是未定义。
这是输出结果:
{"ErrorMessage":null,"Items":[{"ErrorMessage":null,"CategoryCode":"Event Materials","ClassCode":null,"Components":null,"GroupCode":null,"ImageURL":null,"ItemCode":"ITEM-123","ItemDescription":"Old World Lamppost\u000d\u000a\u000d\u000a","ItemName":"GET123","ItemType":null,"KitItem":null,"Matrix":null,"Prefix":null,"RetailPrice":107.990000,"SalesTaxCode":null,"UPCCode":null,"UnitMeasureCode":"EACH","UnitsInStock":0,"Value":null,"WholesalePrice":95.000000}]}
注意
那只是它返回的项目之一。我只发布了一个项目,以便不会太长。