我想知道如何改变一个数组,使它有一个名称。我需要从我的Flutter前端应用程序调用对象。
在本例中,它的名称是"results"。(https://i.stack.imgur.com/lTWMU.png)
这是我的未命名数组:(https://i.stack.imgur.com/vnKJt.png)
这是我的模型类:const db = require('../config/db');
const mongoose = require('mongoose');
const UserModel = require('./user.model')
const { Schema } = mongoose;
const EventSchema = new Schema({
"type": "String",
userId: {
type: Schema.Types.ObjectId,
ref: UserModel.modelName
},
name: {
type: String,
required: [true, "event name can't be empty"],
unique: true,
},
desc: {
type: String,
required: [true, "desc is required"],
},
eventDate: {
type: String,
lowercase: true,
required: [true, "eventDate can't be empty"],
},
pic: {
type: String,
lowercase: true,
required: [true, "pic can't be empty"],
unique: true,
},
price: {
type: Number,
lowercase: true,
required: [true, "price can't be empty"],
},
},{timestamps:true});
const EventModel = db.model('event',EventSchema);
module.exports = EventModel;
你能帮忙吗?提前感谢!!
在这种情况下,您可以创建模型并使用索引值访问这些属性,如
class ArrayModel{
List<InnerItem> listItems;
}
class InnerItem{
String _id;
String nombre;
}
当你想使用这个的时候就获取所有的数据
var data = ArrayModels();
var list = data.listItem;
var singleItem = list[0];//1或2