> For the complete documentation index, see [llms.txt](https://doc.duaer.com/zh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.duaer.com/zh/troubleshooting/code-node-doesnt-return-items-properly.md).

# 在 Duaer 里排查 Code 节点「Code doesn't return items properly」

Duaer 的 Code 节点要求返回条目数组或对象。忘了 return、返回了字符串或数字数组，就会报这几种错。
## Duaer Code 节点的几种报错

- Code doesn't return items properly：Run Once for All Items 模式下没 return，或数组里有字符串、数字。
- Code doesn't return an object：Run Once for Each Item 模式下没返回对象。
- Code doesn't return a single object：Run Once for Each Item 模式下返回了数组。要一条变多条，换成 Run Once for All Items。
- A 'json' property isn't an object：返回了 { json: "文本" } 这种，json 后面必须是对象。
- Unknown top-level item key：同一个数组里有的条目写了 json，有的没写。

## 照这个形状返回

Run Once for All Items 模式：

```
return $input.all().map((item) => ({
  json: { ...item.json, total: item.json.price * item.json.qty },
}));
```

字符串数组先包成对象：return list.map((name) => ({ json: { name } }))。更多见 [在 Duaer 里把数组拆成多条](/zh/snippets/split-array-into-items.md)。
## Questions

### Duaer Code 节点可以直接返回一个对象吗？

可以。Duaer 会把单个对象当成一条输出；返回多条要用数组，每个元素是对象。

### Duaer Code 节点该选哪个模式？

在 Duaer 里，要汇总、拆分或改变条数，用 Run Once for All Items；每条单独加工、条数不变，用 Run Once for Each Item。

## 相关

- [在 Duaer 里用 Code 写一小段逻辑](https://doc.duaer.com/zh/build/code.md)
- [在 Duaer 里把数组拆成多条数据](https://doc.duaer.com/zh/snippets/split-array-into-items.md)
- [理解 Duaer 的数据结构](https://doc.duaer.com/zh/data/data-structure.md)
- [在 Duaer 里使用内置方法和变量](https://doc.duaer.com/zh/code/builtin.md)

