Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在创建一个使用来自 Mongoose 的数据的 API。前端(Backbone)需要 id,而不是 _id。对于这样一个简单的问题,我似乎找不到简单的解决方案。有谁知道将_id重命名为id的方法。我希望这是每个模式的默认行为。
您可以设置一个getItem返回所需字段的模式方法id = _id,如果您真的需要它:)
getItem
id = _id
你有没有想过在前端(Backbone)设置 model.idAttribute 为 _id。这将允许 Backbone '透明地将那个键映射到 id'。
http://backbonejs.org/#Model-idAttribute