小编Dam*_*ian的帖子

Javascript - 从对象中删除未定义的字段

有没有一种干净的方法从对象中删除未定义的字段?

> var obj = { a: 1, b: undefined, c: 3 }
> removeUndefined(obj)
{ a: 1, c: 3 }
Run Code Online (Sandbox Code Playgroud)

我遇到了两个解决方案:

_.each(query, function removeUndefined(value, key) {
  if (_.isUndefined(value)) {
    delete query[key];
  }
});
Run Code Online (Sandbox Code Playgroud)

要么:

_.omit(obj, _.filter(_.keys(obj), function(key) { return _.isUndefined(obj[key]) }))
Run Code Online (Sandbox Code Playgroud)

javascript field object undefined

60
推荐指数
6
解决办法
6万
查看次数

WPF:将列表绑定到ListBox

我有一节课:

public class A : INotifyPropertyChanged
{
    public List<B> bList { get; set; } 

    public void AddB(B b)
    {
        bList.Add(b);
        NotifyPropertyChanged("bList");
    }

    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(string info)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(info));
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

和绑定(UserControl的DataContext是A的实例):

<ListBox ItemsSource="{Binding Path=bList}" />
Run Code Online (Sandbox Code Playgroud)

显示元素,新对象添加到List后ListBox不会更新

将列表更改为ObservableCollection并删除NotifyPropertyChanged处理程序后,一切正常.

为什么列表不起作用?

c# wpf binding listbox observablecollection

11
推荐指数
1
解决办法
2万
查看次数