我在組態檔中有這個打字稿資料:
const filtersTracking = {
[SEARCH_TYPE_ARTICLES]: {
orderBy: {
category: 'Suche Filter Rechtstipps',
action: 'Sortierung Auswahl',
},
practiceAreas: {
category: 'Suche Filter Rechtstipps',
action: 'Rechtsgebiet Auswahl',
},
ratingAverage: {
category: 'Suche Filter Rechtstipps',
action: 'Bewertung Sterne',
},
ratingCount: {
category: 'Suche Filter Rechtstipps',
action: 'Anzahl Bewertungen',
},
publicationYear: {
category: 'Suche Filter Rechtstipps',
action: 'Publikation',
},
isGuide: {
category: 'Suche Filter Rechtstipps',
action: 'Ratgeber',
},
hasVideo: {
category: 'Suche Filter Rechtstipps',
action: 'Video',
},
internationalLaws: {
category: 'Suche Filter Rechtstipps',
action: 'Internationales Recht',
},
},
}
我想做的是獲取“類別”和“動作”資料,我嘗試了以下方法,但沒有一個對我有用:
- 過濾器跟蹤[SEARCH_TYPE_ARTICLES][鍵]
- filtersTracking[SEARCH_TYPE_ARTICLES].key
- filtersTracking[SEARCH_TYPE_ARTICLES].[key]
這里'key'是一個動態變數,我在'key'中獲取資料鍵(例如'orderBy'或'practiceArea')。
public function(key) {
console.log(filtersTracking[SEARCH_TYPE_ARTICLES][key])
}
uj5u.com熱心網友回復:
根據你的評論BTL, export const SEARCH_TYPE_USERS = 'users'; error message : Element implicitly has an 'any' type because expression of type 'string | number' can't be used to index type
這篇文章應該可以幫助你:
元素隱式具有“任何”型別,因為“字串”型別的運算式不能用于索引
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/432655.html
標籤:javascript 打字稿 Vue.js
上一篇:如何通過外鍵過濾搜索?
