小编Edw*_*uay的帖子

如何让 JavaScript 类方法等待构造函数中的数据加载后才返回数据?

如何让该list()方法等待数据加载到构造函数中,然后再将其承诺返回给调用者?

import fetch from 'node-fetch';

class Employees {
    constructor() {
        if (Employees._instance) {
            return Employees._instance
        }
        Employees._instance = this;

        this.employees = [];
        this.dataLoaded = false;

        this.url = 'https://raw.githubusercontent.com/graphql-compose/graphql-compose-examples/master/examples/northwind/data/json/employees.json';

        (async () => {
            const response = await fetch(this.url);
            this.employees = await response.json();
            this.dataLoaded = true;
            console.log(`work done: got ${this.employees.length} employees`);
        })();
    }

    list() {
        return new Promise((resolve) => {
            resolve(this.employees.map(m => `${m.firstName} ${m.lastName} (${m.id})`));
        });
    }

}

const employees = new Employees();

(async () => {
    console.log(await employees.list());
})();
Run Code Online (Sandbox Code Playgroud)

javascript oop class async-await

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

有没有办法将VS.NET中的代码窗口扩展到最大尺寸?

在Eclipse中,您可以双击代码窗口的选项卡并将其扩展为完整大小,例如,如果您只需要处理代码一段时间并希望在较小的监视器上使用最大尺寸等.

有没有办法在一次单击中扩展Visual Studio.NET中的代码窗口(否则我必须折叠工具箱,解决方案资源管理器,属性等)

visual-studio-2008

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

为什么在XAML XmlDataProvider中我们必须说"x:Key"而不是"Key"?

命名空间的功能在这里是什么?

我想在这个简单的例子中我可以放"Key"和"XData"而不是"x:Key"和"x:XData",但是当我这样做时,在XmlDataProvider中找不到"Key".

<Window x:Class="DataBindingWPF.XmlBinding"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="DataBindingWPF" Height="300" Width="300"
    >
    <StackPanel>
        <StackPanel.Resources>
            <XmlDataProvider x:Key="Colors" Source="Colors.xml"  XPath="/colors"></XmlDataProvider>
            <XmlDataProvider x:Key="MoreColors" XPath="/colors">
                <x:XData>
...
Run Code Online (Sandbox Code Playgroud)

wpf xaml

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

如何在LINQ中重新映射属性?

我通过LINQ获取正在运行的进程列表.

我想要的两个属性是"ProcessName"和"WorkingSet64".

但是,在我的UI中,我希望将这些属性称为"ProcessName"和"ProcessId".

如何将名称"WorkingSet64"重新映射为"ProcessId"?

我在下面做了我正在寻找的伪语法:

using System.Linq;
using System.Windows;
using System.Diagnostics;

namespace TestLinq22
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            var theProcesses =
                from p in Process.GetProcesses()
                orderby p.WorkingSet64 descending
                select new { p.ProcessName, p.WorkingSet64 alias "ProcessId" };

            foreach (var item in theProcesses)
            {
                TheListBox.Items.Add(item);
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# linq

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

这是LINQ-to-SQL的一个例子吗?

我用SQL CE数据库制作了一个小WPF应用程序.

我使用LINQ构建了以下代码,以便从数据库中获取数据,这非常简单.所以我认为"这必须是LINQ-to-SQL".

然后我做了"添加项目"并添加了一个"LINQ-to-SQL类".dbml文件,将我的表拖到对象关系设计器上,但它说,"所选对象使用不受支持的数据提供程序."

那么我质疑下面的代码是否实际上是LINQ-to-SQL,因为它确实允许我从我的SQL CE数据库文件中访问数据,但是正式的"LINQ-to-SQL"似乎不支持SQL CE.

那么下面的"LINQ-to-SQL"是不是?

using System.Linq;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Windows;

namespace TestLinq22
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            MainDB db = new MainDB(@"Data Source=App_Data\Main.sdf");
            var customers = from c in db.Customers
                            select new {c.FirstName, c.LastName};
            TheListBox.ItemsSource = customers;
        }
    }

    [Database(Name = "MainDB")]
    public class MainDB : DataContext
    {
        public MainDB(string connection) : base(connection) { }
        public Table<Customers> Customers;
    }

    [Table(Name = "Customers")]
    public class Customers
    {
        [Column(DbType …
Run Code Online (Sandbox Code Playgroud)

c# sql-server-ce linq-to-sql

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

为什么浏览器文本在特定浏览器/机器上会更大?

在我制作的网站上,有人给我发了一个屏幕截图,显示我的字幕字体太大了.

  • 我用FF,IE6,IE7,IE8,Safari/win,opera/win检查了两台机器(Vista)上的网站.
  • 我可以增加浏览器的字体大小,但字幕保持相同的大小(因为它是8pt,如下所示)这是我想要的(因此它不会在徽标下延伸).
  • 它在http://browsershots.org上的34个浏览器屏幕截图中检查正常.

什么可能导致这个人的机器上的字体更大(Windows XP,IE7).他说"所有其他网站看起来都很好".是否有关于Windows XP的操作可以使操作更改浏览器中的字体大小等?或者Windows XP上的arial/italic可能存在问题?

这是它的CSS:

#subtitle {
    position: absolute;
    top: 78px;
    left: 40px;
    width: 738px;
    text-align: right;
    font-size: 8pt;
    font-style: italic;
    font-family: arial;
}
Run Code Online (Sandbox Code Playgroud)

回答:

我将"8pt"更改为"10px",现在适用于他.我假设他已经改变了他机器上的DPI.

html css

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

如何使用C#中的"param"来运行这个例子呢?

我试图理解从RelayCommand示例中获取的这一行中param参数的含义和用法:

return new RelayCommand(param => MessageBox.Show("It worked."));
Run Code Online (Sandbox Code Playgroud)

首先,我理解"param"参数与"params"关键字无关,这是正确的吗?

public int Add(params int[] list)
{
  int sum = 0;
  foreach (int i in list)
    sum += i;
  return sum;
}
Run Code Online (Sandbox Code Playgroud)

其次,我需要添加什么样的委托代码才能使以下示例正常工作?

using System;
using System.Collections.Generic;

namespace TestParam222
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("The total is {0}.", Tools.GetTest(param => 23));
            Console.ReadLine();
        }
    }

    class Tools
    {
        public static string GetTest(List<int> integers)
        {
            return "ok";
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# lambda

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

如何将此TextBlock淡入触发器转换为样式

此XAML使文本在显示时淡入.

我想把这个功能放到Style中.

但是,但是我为"TargetName"添加了什么,因为样式不知道哪个元素将使用它?

如何将此淡入效果转换为样式?

<TextBlock Name="Message" Text="This is a test.">
  <TextBlock.Triggers>
    <EventTrigger RoutedEvent="TextBlock.Loaded">
      <BeginStoryboard>
        <Storyboard>
          <DoubleAnimation
            Storyboard.TargetName="Message" 
            Storyboard.TargetProperty="(TextBlock.Opacity)"
            From="0.0" To="1.0" Duration="0:0:3"/>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </TextBlock.Triggers>
</TextBlock>
Run Code Online (Sandbox Code Playgroud)

wpf xaml styles textblock

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

如何使用泛型将此方法放在父类中?

我有许多复数项目类,每个类都有一个单一项目类的集合,如下所示:

public class Contracts : Items
{
        public List<Contract> _collection = new List<Contract>();
        public List<Contract> Collection
        {
            get
            {
                return _collection;
            }
        }
}

public class Customers: Items
{
        public List<Customer> _collection = new List<Customer>();
        public List<Customer> Collection
        {
            get
            {
                return _collection;
            }
        }
}

public class Employees: Items
{
        public List<Employee> _collection = new List<Employee>();
        public List<Employee> Collection
        {
            get
            {
                return _collection;
            }
        }
}
Run Code Online (Sandbox Code Playgroud)

我可以想象我可以使用泛型将它放到父类中.我怎么能这样做,我想它看起来像这样:

伪代码:

public class Items
{ …
Run Code Online (Sandbox Code Playgroud)

c# generics inheritance

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

如何使RadioButtons像MVVM模式中的ComboBox一样工作?

在以下代码中,用户从ComboBox中选择一个客户,该客户的信息显示在框中.

现在我也想让RadioButtons使用相同的功能.我有RadioButtons来显示客户的ObservableCollection,但我怎样才能让IsChecked工作,即什么相当于SelectedItemRadioButtons

XAML:

<Window.Resources>

    <DataTemplate x:Key="CustomerShowTemplate">
        <Border CornerRadius="5" 
                Background="#eee" 
                Padding="5" 
                HorizontalAlignment="Left">
            <StackPanel>
                <StackPanel Orientation="Horizontal">
                    <TextBlock FontSize="14" FontWeight="Bold" Text="{Binding FirstName}"/>
                    <TextBlock Text=" "/>
                    <TextBlock FontSize="14" FontWeight="Bold" Text="{Binding LastName}"/>
                </StackPanel>
                <TextBlock Text="{Binding Path=HireDate, 
                    StringFormat='Hired on {0:MMM dd, yyyy}'}"/>
            </StackPanel>
        </Border>
    </DataTemplate>

    <DataTemplate x:Key="CustomerComboBoxTemplate">
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="{Binding FirstName}"/>
            <TextBlock Text=" "/>
            <TextBlock Text="{Binding LastName}"/>
        </StackPanel>
    </DataTemplate>

    <DataTemplate x:Key="CustomerRadioButtonTemplate">
        <RadioButton GroupName="CustomerRadioButtonGroup" 
            IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsSelected}">
            <TextBlock Text="{Binding LastName}"/>
        </RadioButton>
    </DataTemplate>

</Window.Resources>

<DockPanel LastChildFill="False" …
Run Code Online (Sandbox Code Playgroud)

wpf xaml radio-button

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