2
我有定義爲一個const CountriesList
國家的數組:製作方法一個鏈與打字稿
[{
name: "Afghanistan",
id: "4",
alpha2Code: "AF",
alpha3Code: "AFG",
numericCode: 4
},
...]
我有這是應該以不同的方式格式化,並過濾國家從上面的常量返回一個靜態類Countries
。
export class Countries {
public static getCountries() {
return CountriesList;
}
public static getFilteredCountries(setName: string) {
return CountriesList
.filter(function (country, index) {
return customFilter(setName, country, index)
});
}
public static formatForSelectInput(items: ICountryIso3166[]) {
return items.map(function (country) {
return {
title: L(country.name),
data: country.id,
value: country.name
};
})
}
}
現在,因爲它是打字稿,它有它自己的規則,我不知道鏈如何方法,使其工作是這樣的:
var countryItems = Countries
.getFilteredCountries('test')
.formatForSelectInput();
我應該創建一個新的對象,從而使不是返回裸數組,而是使用各自的方法返回包裝對象中的數組,或者如何正確執行鏈接?
請指教。