-2

I have some lists of the type ObservableCollection<SampleObject>
They all end with a letter of the alphabet: lista, listb, listc...
Now i want to make a loop which runs through the alphabet and at every letter it should add an item to the current list.

Example:

for (char i = 'a'; i < 'z'; i++)  
{  
    string name = "list" + i;
    name.Add(.....);
}

The "name" in this example should be the list where i want to add an item.


Most browsers will cache modules returned via RequireJS, which is how Durandal obtains its modules and view models.

CTRL+F5 doesn't help because that just refreshes the initial page - all the modules are still requested using javascript (RequireJS), so they are usually pulled from cache first.

I've found it's best to disable caching in your browser's developer tools. Doing so will ensure that all network requests are loaded directly from the source and not from cache.

See this question for additional information: Debugging when using require.js cache

Another solution is configure RequireJS to set its urlArgs property: https://stackoverflow.com/a/8479953/91189

This solution works ok, but makes it harder to debug, at least in Chrome, because breakpoints are lost every time the module is loaded, since it's technically a different file being requested each time.

4

2 に答える 2

5

Dictionary<char, ObservableCollection<SampleObject>>それぞれに異なるコレクションを持つ が必要ですchar

于 2013-05-14T13:50:24.077 に答える
0

リストがクラス レベルで宣言されている場合は、リフレクションを使用してそれらへの参照を取得できます (辞書の方が適切だと思います)。

簡単な例:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private List<string> lista = new List<string>();

    private void button1_Click(object sender, EventArgs e)
    {
        Console.WriteLine("Before:");
        foreach (string value in lista)
        {
            Console.WriteLine(value);
        }

        for (char i = 'a'; i < 'z'; i++)  
        {  
            string name = "list" + i;
            System.Reflection.FieldInfo fi = this.GetType().GetField(name, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public);
            if (fi != null && fi.FieldType.Equals(typeof(List<string>)))
            {
                List<string> referenceToList = (List<string>)fi.GetValue(this);
                referenceToList.Add("Hello!");
            }
        }

        Console.WriteLine("After:");
        foreach (string value in lista)
        {
            Console.WriteLine(value);
        }
    }
}
于 2013-05-14T15:38:30.150 に答える