0

So I'm displaying a observable array in my view, and I want to be able to remove an element from that list using asyncCommand. However, I'm not sure how I should be getting that element. Is there a way of accessing or passing the selected element into the asyncCommand method?

Thanks for the input

mtleising
  • 171
  • 2
  • 14

1 Answers1

1
        addGroupCmd = ko.asyncCommand({
            execute: function (data, complete) {
                //access your observable here with the data object 
                //EX. var demo = data.id();
            },
            canExecute: function (isExecuting) {
                return !isExecuting && isEditing();
            }
        }),

Ok, so I figured it out with it little bit of google's help. All you have to do is pass in the data parameter and ko.lite will figure out what object your talking about. pretty nice, not really sure how it works, but it does.

mtleising
  • 171
  • 2
  • 14
  • what about in the canExecute, can i get data as well ? – Costa Feb 11 '14 at 09:34
  • hmm, are you asking if inside the canExecute method you can get data? Yes, I don't see why not. Maybe you want to call an API to see if a user can still execute. Be careful how you implement that though, because if canExecute get's called a lot, you could be making lots of data call and slowing things down. Does that answer your question? – mtleising Feb 11 '14 at 15:02
  • addGroupCmd = ko.asyncCommand({ execute: function (data, complete) { //access your observable here with the data object //EX. var demo = data.id(); }, canExecute: function (data, isExecuting) { return !isExecuting && isEditing(); } }), this does not work! – Costa Feb 11 '14 at 16:52