In my nosed end app, I have two observational arrays, one place,
self Locations = ko.observableArray ([]). WithIndex ('id');
This includes all the locations that can be linked to a project or not. If the location is not present in the project, then the project ID will be blank.
The other array projects include all the projects in it, if they have any place then there is an array of places in it.
Now what I am trying to do is to get an array with two types of combinations in this way
displayLocations = {location1 = {name = " Abc ", ...} ... they do not have a project location 9 = {name =" xyz ", projectName =" project1 ", ..}}
I I am trying to make a calculated asset for me and then on the visual side, I am planning to use different templates if the project is in place or not.
Any suggestions?
is not sure about withexex
method, but with vanilla KO You can use this in a ko.utils.arrayMap
with a computed
:
. AssociatedLocations = ko.computed (Function () {var dataLoc = this.locations (), dataProj = this.projects (), results = ko.utils.arrayMap (dataLoc, function) {var newObj = loc, project; if (Loc.projectId! == Faucet) {project = ko.utils.arrayFirst (dataProj, function (return) {returnage.id === loc.projectId;}); newObj.projectData = proj;} newObj;}) ; Return result;}, this); // Assume that there is a 'project id' in places. 'Name' property, & amp; An 'ID' will return an array as property project / / / [[name: 'xyz', projectData: {id: ..., projectName: ...}}]
< P> You can test whether a location is related to a project: & lt; Div data-bind = "template: {name: obj.projectData? 'NameIfProject': 'NameIfNoProject'}" & gt; & Lt; / Div & gt;
No comments:
Post a Comment