我正在尝试增加通过索引访问的嵌套数组中的值。有意义的是,Client对象包含Order对象的列表。 Order对象包含int Stars。我的目标是将Stars int增加一个,如:
await mongoContext.Clients.UpdateOneAsync(x => x.Id == model.PostId,
Builders<Client>.Update.Inc(x => x.Orders.ElementAt(0).Stars, 1));
以上代码给出了错误消息: 如果我传递一个确切的数字(不是变量),它可以正常工作:
x => x.Orders[index].Stars
我也尝试过更简单的方法 int numCities = getNumOfCities();
Order currentOrder = data.getCurrentOrder();
if (newValue) {
GraphicsContext gc = canvasCities.getGraphicsContext2D();
gc.clearRect(0, 0, canvasCities.getWidth(), canvasCities.getHeight());
gc.setStroke(new Color(0, 0, 0, 1));
gc.setLineWidth(1);
gc.setFill((Color.GRAY));
for (int i = 0; i < currentOrder.getSize(); i++) {
City current = data.getCities()[currentOrder.getValue(i)];
City next;
if ((i + 1) > numCities - 1) {
next = data.getCities()[currentOrder.getValue(0)];
} else {
next = data.getCities()[currentOrder.getValue(i + 1)];
}
gc.fillOval(current.getX() - 5, current.getY() - 5, 10, 10);
gc.strokeLine(current.getX(), current.getY(), next.getX(), next.getY());
}
if(!(data.getBestEver()==null)) {
Order best = data.getBestEver();
gc.setStroke(new Color(1, 0, 0, 1));
gc.setLineWidth(3);
gc.setFill((Color.GRAY));
for (int i = 0; i < best.getSize(); i++) {
City current = data.getCities()[best.getValue(i)];
City next;
if ((i + 1) > numCities - 1) {
next = data.getCities()[best.getValue(0)];
} else {
next = data.getCities()[best.getValue(i + 1)];
}
gc.fillOval(current.getX() - 5, current.getY() - 5, 10, 10);
gc.strokeLine(current.getX(), current.getY(), next.getX(), next.getY());
}
}
repaint.set(false); //boolean that indicated if something changed and a repaint is necessairy
}
(不是通过&#34; ElementAt()&#34;)但它仍然失败。
欢迎任何帮助。