Airtable - 使用 vue js 格式化 'multiple select' 字段

Airtable - Formatting 'multiple select' fields using vue js

我不是编码员,更像是 'frankencoder' - 了解基础知识,但不太了解更复杂的 JS 内容。因此,只需使用提供的步骤 here 将一些 Airtable 数据嵌入到我可以设置样式的基本 html 格式中。

问题 - Airtable 中的常规文本字段显示正常,'Multiple Select' 和 'Link to another record' 字段显示不稳定,如下所示: 多个Select:["Lunar"] Link到另一条记录:["recRAgEcH3Y3t16md"]

我不太关心 Link 到另一条记录 - 我确信这更复杂,但我希望 Multiple Select 字段正常显示,因为我'您将使用 Airtable 表格提交数据,并希望保留多项选择。

这是 JSFiddle here

JS:

var app = new Vue({
el: '#app',
data: {
items: []
},
mounted: function(){
this.loadItems(); 
},
methods: {
loadItems: function(){
// Init variables
var self = this
var app_id = "---";
var app_key = "---";
this.items = []
axios.get(
"https://api.airtable.com/v0/"+app_id+"/Characters?view=Grid%20view",
{ 
headers: { Authorization: "Bearer "+app_key } 
}
).then(function(response){
self.items = response.data.records
}).catch(function(error){
console.log(error)
})
}
}
})

和 html:

<div id="app">
<ul>
<li v-for="item in items">
<h3>{{ item['fields']['Name'] }}</h3>
<p>Title: {{ item['fields']['Title'] }}</p>
<p><strong>Nickname: </strong>{{ item['fields']['Nickname'] }}</p>
<p><strong>Courts: </strong>{{ item['fields']['Courts'] }}</p>
<p><strong>Kingdoms: </strong>{{ item['fields']['Kingdoms'] }}</p>
<p><strong>Partner: </strong>{{ item['fields']['Partner'] }}</p>
</li>
</ul>            
</div><!--app-->

谢谢!

您将获得 array 个字段,因此您这样做是为了仅显示文本,从而删除括号。

{{ item['fields']['Kingdoms'].join(', ') }}