我试图从一个对象形成一个逗号分隔的字符串,
const data = {"Ticket-1.pdf":"8e6e8255-a6e9-4626-9606-4cd255055f71.pdf","Ticket-2.pdf":"106c3613-d976-4331-ab0c-d581576e7ca1.pdf"};
const values = Object.values(data).map(x => x.substr(0, x.length - 4));
const commaJoinedValues = values.join(',');
console.log(commaJoinedValues);
Run Code Online (Sandbox Code Playgroud)
如何使用TypeScript执行此操作?
获取错误文件:
severity: 'Error'
message: 'Property 'values' does not exist on type 'ObjectConstructor'.'
at: '216,27'
source: 'ts'
Run Code Online (Sandbox Code Playgroud) 我有一个json如下:
[{
"_id": "58a58ea23744cd46918914ef",
"entityId": "ce7200c1-3430-47ce-ab81-7d0622cb8cae",
"name": "Portugal",
"description": "Portugal",
"type": "country",
"category": "common",
"subcategory": "common",
"parent": {
"_id": "58a8486ca4890027348a8966"
},
"image": {
"_id": "58a8486ca4890027348a8965"
},
"metadata": {
"primary": "pt",
"taxRate": 20,
"exchangeRate": 0.7,
"language": "PT",
"currency": "EUR",
"_id": "58a8486ca4890027348a8964"
}
}, {
"_id": "58a58ea23744cd46918914f1",
"entityId": "815b9e90-e36f-4488-ad50-6a259b6d034d",
"name": "Qatar",
"description": "Qatar",
"type": "country",
"category": "common",
"subcategory": "common",
"parent": {
"_id": "58a8486ca4890027348a8969"
},
"image": {
"_id": "58a8486ca4890027348a8968"
},
"metadata": {
"primary": "qa",
"taxRate": 20,
"exchangeRate": 0.7,
"language": "RO",
"currency": "RO",
"_id": …Run Code Online (Sandbox Code Playgroud) 这是我的XAML,在windows手机中,我使用MVVM将数据设置到页面,但我在列表框中找不到任何数据.
<ListBox Grid.Row="0" SelectionMode="Single" SelectedItem="{Binding CurrentSelectedEmployee, Mode=TwoWay}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding FirstName}"></TextBlock>
<TextBlock Width="5"></TextBlock>
<TextBlock Text="{Binding LastName}"></TextBlock>
</StackPanel>
<TextBlock Text="{Binding Description}" TextWrapping="Wrap"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
而我的ViewModel,
public MainViewModel()
{
Employees = new ObservableCollection<Model.Employee>();
}
public bool IsLoaded { get; set; }
public void LoadData()
{
Employees = CompanyDataPhone.Service.EmployeeService.GetEmployees();
IsLoaded = true;
}
// public ObservableCollection<Model.Employee> Employees { get; set; }
public ObservableCollection<CompanyDataPhone.Model.Employee> _employees;
public ObservableCollection<CompanyDataPhone.Model.Employee> Employees
{
get {
return _employees;
}
set
{
_employees …Run Code Online (Sandbox Code Playgroud)