我创建了Vue应用程序,并且有简单的存储库:
const paginationStore = {
data: {
entitiesDisplayOptions: [
{ value: '1', text: '1' },
{ value: '2', text: '2' },
{ value: '4', text: '4' },
{ value: '999999', text: 'All' },
],
paginationLimits: {
bottom: 0,
top: paginationStore.data.entitiesDisplayOptions[0].value
}
}
}
我遇到错误:
未捕获的TypeError:无法读取未定义的属性'data'
为什么我不能将entityDisplayOptions中的值设置为paginationStore.data.paginationLimits.top?我应该怎么做才能使其正常工作?
答案 0 :(得分:0)
您可以将其存储在定义之外的变量中:
// GET: api/Partenaires_prestations
[Authorize]
[Route("api/Partenaires_prestations")]
public List<PartenaireMapItem> GetPartenairesWithPrestations() {
Random rnd = new Random();
var queryString = Request.GetQueryNameValuePairs();
var prestation = queryString.FirstOrDefault();
return db.Partenaires.Where(p => p.PartenairePrestations.Any(pp => pp.Prestation.NomPrestation == prestation.Value))
.ToList()
.Select(p => new PartenaireMapItem {
IdPartenaire = p.IdPartenaire,
FirstName = p.FirstName,
LastName = p.LastName,
NomComplet = p.LastName.Substring(0,1).ToUpper() + ". " + p.FirstName,
Type = p.Type,
DureeMin = 50,
Lat = p.Lat,
Lng = p.Lng,
ImageUrl = p.ImageUrl,
SeDeplace = p.SeDeplace,
ADomicile = p.ADomicile,
Notes = p.NoteClientPartenaires,
Prestations = p.PartenairePrestations.Select(y => y.Prestation.NomPrestation).ToList();
}).ToList();
}
答案 1 :(得分:0)
有很多可能性。您要做的就是记住,在创建对象时,不能以对象文字的形式引用其他对象属性。
const entitiesDisplayOptions = [
{ value: '1', text: '1' },
{ value: '2', text: '2' },
{ value: '4', text: '4' },
{ value: '999999', text: 'All' },
]
const paginationLimits = {
bottom: 0,
top: paginationStore.data.entitiesDisplayOptions[0].value
}
const paginationStore = {
data: {
entitiesDisplayOptions,
paginationLimits
}
}