I want to parse specific element from an existing viewModel and put it into a new array.
I have an applications viewModel which has tons of information of applicants. It is called in the following way:
self.applications = ko.observableArray(@Html.Json(Model.ApplicationCompatibilities.Select(o => o.JsonForm)) || []);
So the "application" object has several elements in it as shown in the attached image above.
What I wanted to do was, I wanted to retrieve only the "applicationKey" element into a new array. So what I did was :
self.previewApplication = ko.computed(function () {
return ko.utils.arrayFilter(self.applications(), function (i) {
return i.application.applicationKey;
});
});
I intended to loop through the "self.applications()" viewModel and return only the "application.applicationKey". But what I actually get by doing that is:
I am just getting the same "applications" object inside the new viewModel. How can I get an array of only the "application.applicationKey" ?
Thanks! Please Help!
EDIT:
This works now! Now my viewModel.previewApplication() gives me a list of applicationKey's. Now what I want to do is, I want to add a link that loads a modal. And inside that modal I want to display the specific "application" that has a specific "applicationKey"
For example, the link to the modal will look like this:
<a href="#" data-toggle="modal" data-target="#previewApplicantModal" data-bind="attr: { 'data-applicationKey': application.applicationKey }">
Preview Application
</a>
So If I inspect the element of the link, it has a new data-binding:
<a href="#" data-toggle="modal" data-target="#previewApplicantModal" data-bind="attr: { 'data-applicationKey': application.applicationKey }" data-applicationkey="abc976cfx">
Preview Application
</a>
Finally I want to loop through the "application" object and return only "one" element of the object that has "abc976cfx" as its applicationKey.
Is there an easy way of doing this? I attached a screenshot for better explanation.


