I try to use custom handlebars helper:
/**
* Bound Conditional if/else Block
*
* Executes the given block if all arguments are equal
* NOTE: this helper is meant to be used by other helpers by specifying
* a callback as the `conditional` option
*/
export default function() {
var args = [].slice.call(arguments);
var options = args.pop();
var context = (options.contexts && options.contexts[0]) || this;
// Find all unique values in the array; if one is left, they were all equal
options.conditional = function(results) {
return results.uniq().length === 1;
};
// Gather all bound property names to pass in order to observe them
var properties = options.types.reduce(function(results, type, index) {
if (type === 'ID') {
results.push(args[index]);
}
return results;
}, []);
// Resolve actual values for all params to pass to the conditional callback
var normalizer = function() {
return Ember.Handlebars.resolveParams(context, args, options);
};
// This effectively makes the helper a bound helper
// NOTE: 'content' path is used so that multiple properties can be bound to using the `childProperties` argument,
// however this means that it can only be used with a controller that proxies values to the 'content' property
return Ember.Handlebars.bind.call(context, 'content', options, true, options.conditional, normalizer, properties);
}
inside each loop
{{#each field in formConfig.fields}}
{{#ifCond field.type 'input-field'}}
{{#input field.name class="form-group"}}
{{#input field.name class="form-group"}}
{{label-field field.name text=field.label class="control-label col-sm-3"}}
<div class="input-wrapper col-sm-9">
{{input-field field.name class="form-control" placeholder=field.placeholder}}
</div>
{{/input}}
{{field.type}}<br />
{{/input}}
{{/ifCond}}
{{/each}}
Inside helper function I get params as string. But I can't find how get access for 'field' from helper function?
I try 'context', 'options.data.view' - neither allow get field data
If I pass item as param
{{#ifCond field 'type' 'input-field'}}
args contains array of strings
["field", "type", "input-field"]
The main question : how to get access for wrapper context inside helper function ( get item inside helper ) ?
Aucun commentaire:
Enregistrer un commentaire