尝试访问小胡子中的数组 javascript
Trying to access am array in mustache javascript
我正在尝试使用 this.location.coordinates.0:
从 mustache 访问一个数组
<div class="block">
<label>Location (longitude/latitude):</label> {{location.coordinates.0}}/{{location.coordinates.1}}
</div>
并得到以下错误
ERROR: POST /abduction/create Error: \views\abduction\abduction-detail.hbs: Parse error on line 4:
...ocation.coordinates.0
模型看起来像这样:
const abductionSchema = new Schema(
{
//https://mongoosejs.com/docs/geojson.html
location: {
type: {
type: String, // Don't do `{ location: { type: String } }`
enum: ['Point'], // 'location.type' must be 'Point'
required: true
},
// Note that longitude comes first in a GeoJSON coordinate array, not latitude.
coordinates: {
type: [Number],
required: true
}
},
locationName: String,
timeDate: Date,
pictures: [String],
description: String,
reporter: { type: Schema.Types.ObjectId, ref: 'User' }
},
{
// this second object adds extra properties: `createdAt` and `updatedAt`
timestamps: true,
}
);
如果我使用:location.coordinates.[0]
我正在尝试使用 this.location.coordinates.0:
从 mustache 访问一个数组<div class="block">
<label>Location (longitude/latitude):</label> {{location.coordinates.0}}/{{location.coordinates.1}}
</div>
并得到以下错误
ERROR: POST /abduction/create Error: \views\abduction\abduction-detail.hbs: Parse error on line 4:
...ocation.coordinates.0
模型看起来像这样:
const abductionSchema = new Schema(
{
//https://mongoosejs.com/docs/geojson.html
location: {
type: {
type: String, // Don't do `{ location: { type: String } }`
enum: ['Point'], // 'location.type' must be 'Point'
required: true
},
// Note that longitude comes first in a GeoJSON coordinate array, not latitude.
coordinates: {
type: [Number],
required: true
}
},
locationName: String,
timeDate: Date,
pictures: [String],
description: String,
reporter: { type: Schema.Types.ObjectId, ref: 'User' }
},
{
// this second object adds extra properties: `createdAt` and `updatedAt`
timestamps: true,
}
);
如果我使用:location.coordinates.[0]