我正在构建带有主干的文件浏览器,并在保存获取的集合时遇到问题。来自服务器的 JSON 响应被触发,如下所示:
[{"name":".","type":"d"},{"name":"..","type":"d"},{"name":"bolt","type" :"d"},{"name":"crm","type":"d"},{"name":"crm_backup","type":"d"},{"name":"解析。 php","type":"f"},{"name":"places.txt","type":"f"},{"name":"pyrocms","type":"d"}, {"name":"test.php","type":"f"},{"name":"time_test.php","type":"f"},{"name":"wordpress","类型":"d"}]
我在我的收藏中检查了 parse ,它有 11 个元素。但是当我输出我的收藏时它是空的。这是收集代码:
var File = Backbone.Model.extend({
defaults: {
'name': '',
'type': 'f'
}
});
var FilesCollection = Backbone.Collection.extend({
model: File,
url: '<?php echo site_url('files/dir/'); ?>',
parse: function(response) {
console.log("In prase " + response.length);
return response[0];
}
});
var files = new FilesCollection();
files.fetch({data: {dir: '/home/stamp/public_html/'}}, {rest: true});
console.log(JSON.stringify(files));