我有两个对象:
{
"_id" : ObjectId("54be5f5528c13bfc3409e8c2"),
"name" : "Antonio",
"lastname" : "de Cabezón",
"by" : 1510,
"dy" : 1566,
"country" : "spain",
"genre" : [
"classical",
"baroque"
]
}
{
"_id" : ObjectId("54be5f5528c13bfc3409e8c1"),
"name" : "Guillaume-Antoine",
"lastname" : "Calvière",
"by" : 1695,
"dy" : 1755,
"country" : "france",
"genre" : [
"baroque"
]
}
Run Code Online (Sandbox Code Playgroud)
当我执行db.currentdb.find({genre:'baroque'})时,它也返回第一个对象.
我想只获取类型只是"巴洛克"的对象.这样做的正确方法是什么?
我列出了Animal如下s:
ArrayList<Animal> animals = new ArrayList<Animal>();
animals.add(new Animal(1, "animal1", 50, "10 Janvier 2016", "Noir", 4, true));
animals.add(new Animal(2, "animal2", 50, "10 Janvier 2016", "Noir", 4, true));
animals.add(new Animal(3, "animal3", 50, "10 Janvier 2016", "Noir", 4, true));
animals.add(new Animal(4, "animal4", 50, "10 Janvier 2016", "Noir", 4, true));
animals.add(new Animal(5, "animal5", 50, "10 Janvier 2016", "Noir", 4, true));
Run Code Online (Sandbox Code Playgroud)
我想ArrayList用他们的身份证明我的动物名单.从我所见,我必须使用比较器.
这是我到目前为止创造的......
public class ComparatorAnimal implements Comparator<Animal> {
public int compare(Animal animals.get(0), Animal animals.get(1) {
return animals.get(0).idAnimal - animals.get(1).idAnimal;
}
Run Code Online (Sandbox Code Playgroud) 我试图用整数做一个金字塔.IE数字3:
3
33
333
Run Code Online (Sandbox Code Playgroud)
所以基于我发现的答案,我做了这个:
int n = 8;
String n2 = Integer.toString(n);
for (int i=0; i<n; i++) {
System.out.println(StringUtils.repeat(n2, i));
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用,并且不是最理想的.有一种简单的方法可以在同一行中重复整数n次吗?
编辑:自己做了一个方法..开心不起来要么但似乎我不能只用类似的System.out.println(INT X,INT n次)
int n = 8;
for (int i=0; i<=n; i++) {
for (int j=0; j<i; j++) {
System.out.print(n + " ");
}
System.out.println("");
}
Run Code Online (Sandbox Code Playgroud) 我有两个字符串:
String a = "11111";
String b = "10001";
Run Code Online (Sandbox Code Playgroud)
我想和"&"运营商进行比较.
最好的方法是什么?
我有一个功能可以删除表单中在 Firefox 中有效但在 Chrome 中无效的字段。
function activeDelete(del) {
$('[data-delete="' + del + '"]').click(function(event) {
deleteField(event);
});
}
function deleteField(event) {
if ((members - 1) >= 3) {
members -= 1;
var i = $(event.target).data('delete');
console.log(i)
var currentdiv = $('[data-div="' + i + '"]');
currentdiv.remove();
$("#rollWheel").val("Roll the wheel ! (" + members + " members)");
} else {
$('.errors').remove();
$('#firstCard').append('<div class="errors animated fadeOut">3 participants minimum.</div>');
}
}
activeDelete(1);
Run Code Online (Sandbox Code Playgroud)
我记录了我的i变量,它是undefined(在 Chrome 中)。我在本地和我的网站上进行了测试。
我在这里缺少什么?
我有一个javascript函数:
function isInSupplier(idsupplier) {
suppliers.forEach(function(object) {
if (object._id == idsupplier) {
console.log("TRUE");
return true;
};
});
return false;
Run Code Online (Sandbox Code Playgroud)
我有一个产品清单,每个都有供应商.我想列出一个独特的供应商列表,因此供应商已经在我的供应商列表中,我不会添加新的供应商.
这是我的功能:
console.log(isInSupplier(('<s:property value="supplier.id" />')));
if (!isInSupplier(('<s:property value="supplier.id" />'))) {
suppliers.push(new supplier(
('<s:property value="supplier.id" />'),
('<s:property value="supplier.supplier_name" />'),
('<s:property value="supplier.type" />'),
('<s:property value="supplier.phone" />')
));
}
Run Code Online (Sandbox Code Playgroud)
还有一些我不明白的事情:即使控制台正确地记录"TRUE",该功能也不会返回true.在我的第二个代码块中,我有另一个控制台日志; 总是记录错误.
我错过了什么?