I've got the following associative array that I made using Knockout.js.
self.users = ko.observableArray([{name: "Unassigned", value: null}]);
At some point in the application when a button is clicked I have to begin adding more values to this array. However, I'm not quite sure how to do that. Before, I was just using a generic array like so:
$.each(data.users, function(index, user)
{
vm.users.push(user.first_name + " " + user.last_name);
});
Now that I've got to deal with multiple values I'm not sure how to push both the item and the value to the array. Is there an easy way to do this?
Update:
Following Milimetric's suggestion I updated my code to the following:
vm.users.push({name: user.first_name + " " + user.last_name, value: index + 1});
I then went back and updated my view to the following:
<select id="ticket_assignee" name="ticket[assignee]" data-bind="options: users.name, value: assignee"></select>
Prior to updating the view I was getting the correct number of items in the dropdown. After updating the view I just have a single value which says "d". My guess is that the d comes from the last letter in Unassigned. Did I do something wrong that caused the values to not display correctly?