mikeric / rivets

Lightweight and powerful data binding.
http://rivetsjs.com
MIT License
3.23k stars 310 forks source link

Passing arguments in plain Object #284

Open ankurp opened 10 years ago

ankurp commented 10 years ago

I have a plain javascript object that has a getURL method and want to pass an argument to it when it is called.

I am doing rv-href="model.getURL < model" which calls the getURL but does not pass model in the arguments of the function

kayhadrin commented 10 years ago

The < character is used to indicate a dependency to another model property. It's not used to pass additional parameters.

I think you may have a problem with your rivet adapter. The code that subscribes to model changes.

Please add a code example of your issue on jsfiddle or something similar so that the problem is easier to debug. On 13 Mar, 2014 4:03 AM, "Ankur Patel" notifications@github.com wrote:

I have a plain javascript object that has a getURL method and want to pass an argument to it when it is called.

I am doing rv-href="model.getURL < model" which calls the getURL but does not pass model in the arguments of the function

— Reply to this email directly or view it on GitHubhttps://github.com/mikeric/rivets/issues/284 .

janvennemann commented 10 years ago

Consider using a formatter. You can pass as many arguments as you like.

<a rv-href="model | getURL arg1 arg2">Click</a>

And define the formatter like this:

rivets.formatter.getURL = function(value, arg1, arg2) {
    // note: value is your model
    return 'generate your url here';
}