1

I have an observable array that holds a list of people and a table that displays their first name, with a select button for each. When the user clicks the select button I'd like another element on screen to display the person's full name. Is there a way to get it so that if a person is removed from the array, it also removes the element displaying their full name?

jsFiddle example here

Edit: I can achieve this by putting self.SelectedPerson(false); in the remove function, but is there a better way of doing it?

2nd Edit: Changed the jsFiddle

1 Answer 1

1

One useful thing here is that in the click method in a foreach loop you get the current data item sent to the function, which means that you can set the SelectedAccount observable to the item sent to the function.

Check this updated jsFiddle: http://jsfiddle.net/jCkuY/1/

And for the remove function you can either set the selectedAccount to an empty Account object or even to null, but then you'll need to use an if binding perhaps.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the reply. I've changed my example (forgot to hit update!). It feels this way that changing the Selected observable to null/empty/false is surplus. Is there a better way to have this so that the call to remove it from the array will also automatically change that observable based on the element that has been removed??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.