Created
July 31, 2013 10:30
-
-
Save alovak/6120984 to your computer and use it in GitHub Desktop.
CoffeeScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class KoModel | |
indexed_error_for: (property_name, index, nested_property = null) => | |
ko.computed(=> | |
if @errors() && @errors()[property_name] | |
error = jQuery.grep @errors()[property_name], (item) -> item.index == index | |
return '' unless error && error.length | |
if nested_property | |
@join_errors error[0].errors[nested_property] | |
else | |
@join_errors error[0].errors) | |
error_for: (property_name) => ko.computed(=> @join_errors @errors()[property_name] if @errors()?) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jQuery.grep(this.errors()[property_name], function(item) { return item.index == index; });
Выглядит не менее shit. Такое чувство что автор изо всех сил пытался сделать код нечитаемым, делая как можно больше «однострочников».