where data.SelectedReminder is defined..

Feb 5, 2013 at 1:20 PM
Hi,
In mstat.reminders.js, data is a ReminderDetailsViewModel object, as GET: /Reminder/List/1 returns
ReminderDetailsViewModel
{VehicleList,
Reminder,
Reminders}.

I can't understand where SelectedReminder of data.SelectedReminder is defined..
Code from mstat.reminders.js
_updateSelectedReminder: function () {
            var selectedReminderId = this.options.selectedReminderId,
                data = this.data,
                reminder,
                i;
            if (data.Reminders && data.Reminders.length) {
                if (selectedReminderId > 0) {
                    for (i = 0; i < data.Reminders.length; i += 1) {
                        reminder = data.Reminders[i];
                        if (reminder.ReminderId === selectedReminderId) {
                            data.SelectedReminder = reminder;
                            break;
                        }
                    }
                } else {
                    data.SelectedReminder = data.Reminders[0];
                    this._setOption('selectedReminderId', data.SelectedReminder.ReminderId);
                }
            }
        }
Thanx in advance for help and guidance as always.
Developer
Feb 5, 2013 at 10:38 PM
Edited Feb 5, 2013 at 10:42 PM
Hi,

Based on my understanding the SelectedReminder attribute is defined in this same script you mentioned when entering the else clause at the end of the script:
  else {
                    data.SelectedReminder = data.Reminders[0];
                    this._setOption('selectedReminderId', data.SelectedReminder.ReminderId);
    }
In order to follow this, I believe you could debug this script by using a tool such as Windows Internet Explorer® F12 developer tools , Fiddler , or FireBug in which case you may find that this attribute is undefined until the aforementioned point.

Regards,

Agustin Adami
http://blogs.southworks.net/aadami
Feb 7, 2013 at 11:22 AM
@aadami

Hi,
Actually my doubt is something else, since data contains ReminderDetailsViewModel {VehicleList, Reminder, Reminders} as GET: /Reminder/List/1 returns
ReminderDetailsViewModel.
So we can access VehicleList, Reminder, Reminders like data.VehicleList, data.Reminder, data.Reminders. But there is no SelectedReminder
in ReminderDetailsViewModel.

Then where from
SelectedReminder in data.SelectedReminder.ReminderId coming.

Reagrds
Feb 8, 2013 at 12:47 PM
Hi,
I got it..
var viewModel = new ReminderDetailsViewModel
            {
                VehicleList = new VehicleListViewModel(vehicles, vehicle.VehicleId) { IsCollapsed = true },
                Reminder = ToFormModel(reminders.FirstOrDefault()),
                Reminders = new SelectedItemList<ReminderSummaryModel>(list, Enumerable.FirstOrDefault),
            };
and SelectedItemList :
public SelectedItemList(IEnumerable<T> source, T selectedItem)
        {
            List = source;
            SelectedItem = selectedItem;
        }
Thanks for your initial reply. And for me this project is a great source of learning.