【发布时间】:2019-07-11 10:34:09
【问题描述】:
我有一个 Firebase 数据库,其中有几个对象及其属性。
{
"products": [{
"sku": "70741",
"name": "Name",
"image": "name.png",
"quantity": 12,
"price": {
"value": 2.10,
"type": "simple"
},
"attributes": {
"0": "2",
"1": "4",
"2": "2|1|3",
"3": "1|2",
"4": "2",
"5": "6|7"
}
}
],
"attributes": [{
"id": 0,
"name": "name1",
"type": "type1"
},
{
"id": 1,
"name": "name2",
"type": "type2"
},
{
"id": 2,
"name": "name3",
"type": "type1"
}
],
"attributesIdValue": [
"companyName1|companyName2|companyName3|companyName4",
"typeName1|typeName2|typeName3|typeName4",
"address1|address2|address3|address4",
"1|2|3",
"country1|country2|country3|country4",
"number1|number2|number3|number4"
]}
products.attributes 中的键应该指向 attributes.id 和 attributesIdValue.id,products.attributes 中的 value 应该指向 attributesIdValue,具体取决于它的 id 和 value。
我怎样才能用 vue.js 得到这样的东西:
product.attributes.0 应该显示这个产品的companyName
product.attributes.1 应该显示此产品的typeName
product.attributes.2 应该显示此产品的address
{{ product.price.value }}工作并显示值,但我无法访问这些属性。
------- 编辑 换句话说,我想要的是这样的东西,而不是上面的:
"products": [{
"sku": "70741",
"name": "Name",
"image": "name.png",
"quantity": 12,
"price": {
"value": 2.10,
"type": "simple"
},
"attributes": {
"attributes.0": "attributesIdValue.2",
"attributes.1": "attributesIdValue.4",
"attributes.2": "attributesIdValue.2|attributesIdValue.1|attributesIdValue.3",
"attributes.3": "attributesIdValue.1|attributesIdValue.2",
"attributes.4": "attributesIdValue.2",
"attributes.5": "attributesIdValue.6|attributesIdValue.7"
}
}
],
"attributes": [{
"id": 0,
"name": "name1",
"type": "type1"
},
{
"id": 1,
"name": "name2",
"type": "type2"
},
{
"id": 2,
"name": "name3",
"type": "type1"
}
],
"attributesIdValue": [
"companyName1|companyName2|companyName3|companyName4",
"typeName1|typeName2|typeName3|typeName4",
"address1|address2|address3|address4",
"1|2|3",
"country1|country2|country3|country4",
"number1|number2|number3|number4"
]}
这会输出那些里面的数据。
【问题讨论】:
-
您是否尝试访问
attributesIdValue或attributes? -
btw 产品和
attributesIdValue的关系是什么?你怎么知道应该使用product.attributes.1返回哪个typeName(typeName1| typeName2| typeName3)? -
@SimonThiel 两者。
product.attributes键(例如“0”:“2”,其中0是键,2是值)应该让我从attributes.id得到一个值,即0和product.attributes值应该让我从0位置开始的第二个值是companyName2@aquilesb我不确定我说的是否清楚,但product和attributes和attributesIdValue之间应该有联系。product.attributes.1应该返回"1": "4",所以在这种情况下,key 会得到我"id": 1, "name": "name2", "type": "type2"而 value 会得到我typeName4。