我在HTML中设置了服务器端的模型数据:
<head>
<script>
window.GlobalExpress = {
modelData: { ... },
collectionData: [ ... ]
};
</script>
</head>
我希望能够用它来初始化Restangular模型,这是我能够的方式,回到骨干时代:
var SpecialModel = Backbone.Model.extend({ ... });
var aModel = new SpecialModel(GlobalExpress.modelData);
var SpecialCollection = Backbone.Collection.extend({ ... });
var aCollection = new SpecialCollection(GlobalExpress.collectionData);
有可能吗?
答案 0 :(得分:0)
是的,它可以:
var user = Restangular.all('users');
_.extend(user, Restangular.restangularizeCollection(null, objectData, 'users'));