{"issue":{"state":"open","pull_request":{"diff_url":null,"html_url":null,"patch_url":null},"milestone":null,"user":{"avatar_url":"https://secure.gravatar.com/avatar/f3018d14b9c3d18e7c10ce34215b0f6c?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"f3018d14b9c3d18e7c10ce34215b0f6c","url":"https://api.github.com/users/dswitzer","login":"dswitzer","id":900497},"updated_at":"2011-10-30T07:53:47Z","labels":[],"assignee":null,"comments":19,"closed_at":null,"url":"https://api.github.com/repos/derickbailey/backbone.modelbinding/issues/28","body":"I'd love to see a way to trigger a callback function for updating HTML elements (non-form elements.) \r\n\r\nA couple of use cases:\r\n\r\n* Applying a formatting mask to input\r\n* Creating a mailto: link for an e-mail address\r\n\r\nThe simplest solution to implement would probably be to add another data-bind formatting option, so you could do:\r\n\r\n```\r\n<div id=\"user-email\" data-bind=\"fn:window.formatEmail email\"></div>\r\n```\r\n\r\nThe you'd then write your function like:\r\n\r\n```\r\nfunction formatEmail(element, value){\r\n  var $a = $(\"a\").attr(\"href\", \"mailto:\" + value).text(value).appendTo(element);\r\n}\r\n```\r\n\r\nThis would give you complete control over everything. I'd prefer a way to map a callback function directly within the view itself, so that all my JS logic is in one place, but this would probably be the easiest way to get something into the code.","html_url":"https://github.com/derickbailey/backbone.modelbinding/issues/28","title":"Format callback for bound HTML elements","number":28,"id":1878157,"created_at":"2011-10-11T16:35:20Z"},"action":"created","comment":{"user":{"avatar_url":"https://secure.gravatar.com/avatar/777447906f773b19a9886d444cbb2401?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"777447906f773b19a9886d444cbb2401","url":"https://api.github.com/users/blocka","login":"blocka","id":43194},"updated_at":"2011-10-30T07:53:47Z","url":"https://api.github.com/repos/derickbailey/backbone.modelbinding/issues/comments/2568636","body":"A couple of ideas to throw out here:\r\n1) To address something similar, I introduced a concept of \"virtual attributes\", whereas I have `Backbone.Model.prototype.get` also search for a `getXXXXXX` method on the model. Using this, you can put the formatting on the model, in a \"virtual attribute\", and use that in your binding. In my current implementation, you have to manually add change bindings though to let anything (like Backbone.ModelBinding) know that something has changed...which kind of sucks.\r\n\r\nNow one can say that this is an abuse of Backbone models, but we all know the solution to this by now....ViewModels. Anyway we shouldn't be sticking our Backbone models directly into the views, we should be sending ViewModels, tailor made for the view in question. \r\n\r\nOf course, now eventually you would have to update the actual model, which sort of defeats the purpose of using ModelBinding. \r\n\r\nI do think I am on to something here though.... \r\n","id":2568636,"created_at":"2011-10-30T07:53:47Z"}}