ojek
ojek

Reputation: 10088

KnockoutJS - attr binding $data not working

I have this:

<a href="javascript:void(0);" data-bind="attr: { onclick: 'CreateChatWindow(\'$data.peer\');'}" class="socialsChat"><img src="~/Content/Styles/Default/Images/Icons/chat.png"/></a>

Now, the output looks like that:

<a href="javascript:void(0);" class="socialsChat" onclick="CreateChatWindow('$data.peer');"><img src="~/Content/Styles/Default/Images/Icons/chat.png"/></a>

Why isn't $data.peer getting it's value from my model?

Upvotes: 0

Views: 277

Answers (1)

nilphilus
nilphilus

Reputation: 620

First, why 'onclick'? this should be 'click', at least I'm using this at newest version. Second, why you use \'? and third, passing arguments to viewmodel methos looks like this

data-bind="click: function() { CreateChatWindow($data); }"

Upvotes: 1

Related Questions