小编Itz*_*ive的帖子

REST api中项目的用户特定数据

在REST api中,处理项目的用户特定数据的最有效方法是什么?

例如,假设有些item资源可以受到青睐.可以通过以下方式访问项目列表:

https://myservice.com/api/items (Full list)
https://myservice.com/api/items/{id} (Single item)
Run Code Online (Sandbox Code Playgroud)

哪个回报

{
  { 'name': 'name 1' },
  { 'name': 'name 2' },
}
Run Code Online (Sandbox Code Playgroud)

每个项目都可以受到用户(https://myservice.com/api/user/{id})的青睐,这些收藏的列表可以在以下位置获得:

https://myservice.com/api/user/{id}/favorites
Run Code Online (Sandbox Code Playgroud)

整个设置是无状态的; 但是,可能有数百个收藏夹,并且可能不需要检索完整列表.

问:在维护无状态系统的同时,将项目与用户特定数据相结合的最佳方法是什么?

即获得用户特定的项目列表是否合理或合理:

https://myservice.com/api/items?user={id}
{
  { 'name': 'name 1', 'isFavourite':true },
  { 'name': 'name 2', 'isFavourite':false },
}
Run Code Online (Sandbox Code Playgroud)

api rest stateless

6
推荐指数
1
解决办法
390
查看次数

自动选择添加到ObservableCollection的项目

每当将一个项添加到ObservableCollection时,我都会尝试自动选择ListView中的项.我正在使用CollectionChanged事件来监听添加项目的时间,然后选择它.CollectionChanged事件似乎在UI更新之前发生,因此SelectedIndex会相应调整.我已经尝试设置SelectedIndex和SelectedItem,但在两种情况下,添加的项目最终都被选中.正确的索引是更改集合的时间,UI更新,然后ListView增加索引.

这种现象可以通过以下方式证明:

<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" DataContext="{Binding Main, Source= {StaticResource Locator}}">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="30"/>
        </Grid.RowDefinitions>
        <ListView ItemsSource="{Binding Items, Mode=TwoWay}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" SelectedIndex="{Binding SelectedIndex, Mode=TwoWay}" Grid.Row="0">
        </ListView>
        <StackPanel Orientation="Horizontal" Grid.Row="1">
            <Button Content="Add Item" Width="75" Command="{Binding AddItemCommand}"/>
            <Label Content="SelectedIndex:"/>
            <Label Content="{Binding SelectedIndex}"/>
            <Label Content="SelectedItem:"/>
            <Label Content="{Binding SelectedItem}"/>
            <Label Content="&lt;- Numbers should match after item added"/>
        </StackPanel>
    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

和ViewModel:

public class MainViewModel : ViewModelBase
{
    private ICommand addItemCommand;
    /// <summary>
    /// Initializes a new instance …
Run Code Online (Sandbox Code Playgroud)

c# wpf listview observablecollection mvvm

1
推荐指数
1
解决办法
4246
查看次数

标签 统计

api ×1

c# ×1

listview ×1

mvvm ×1

observablecollection ×1

rest ×1

stateless ×1

wpf ×1