【发布时间】:2012-05-20 22:33:27
【问题描述】:
有没有办法通过给 fetch() 提供初始模型参数来获取集合。
澄清一下:我有一个具有 name(作为字符串)和 numbers(array) 属性的模型 Human。我想在我的数据库中找到所有具有给定数字数组的人。 (示例: 我的数组中有 [123,342,4],对于每个数字,我想提取人名)。
我创建了一个 Human 集合,模型是 human。当我像这样获取时,它不会导致任何问题;
humanCollection.fetch({
success:function(model,response){
console.log(model.toJSON().length);
var arr=model.toJSON();
for(var i=0;i<arr.length;i++)
console.log(arr[i].humanName+" ");
console.log("Success");
},
error:function(model,response){
console.log(response);
console.log("Failure");
}
});
我正在考虑创建一个没有名称而只有数字的 dummy 人类对象,然后将数字传递给我的 php 但 .fetch()当我将参数放在开头时, 函数似乎不起作用。甚至下面的代码也不起作用;
humanCollection.fetch({},{
success:function(model,response){
console.log(model.toJSON().length);
var arr=model.toJSON();
for(var i=0;i<arr.length;i++)
console.log(arr[i].humanName+" ");
console.log("Success");
},
error:function(model,response){
console.log(response);
console.log("Failure");
}
});
可能是什么问题?为了检索具有给定数字的人类集合,我创建一个虚拟人体模型是否合乎逻辑。这是我能想到的传输特定所需 json 数据的唯一方法。
【问题讨论】:
标签: php json collections backbone.js