我在模板中调用了一个组件。该组件的工作是从数据库表生成字段。我有像field_name,field_data_table,field_key,field_value等
的值这些是通过“内容”,即
提交给组件的{{module-add-parameter content=model create=(action "addParameters") value=fields}}
// components / module-add-parameter。这将生成表单字段并输出任何所需数据,即选择选项。
<form {{action 'create' on='submit' }}>
{{#each content.fields as |field|}}
{{form-field type=field.field_type content=field.data_table label=field.field_name key=field.data_key value=field.data_value width=field.field_width saveTo=field.data_to_column placeholder=field.field_placeholder multiple=field.field_multiple}}
{{/each}}
<button type="submit" class="btn btn-primary">Add Parameter</button>
</form>
// components / form-field / template.hbs
{{#if (eq type "select")}}
{{form-field/field-select content=content name=saveTo label=label key=key value=value width=width saveTo=saveTo multiple=multiple placeholder=placeholder}}
{{/if}}
{{#if (eq type "text")}}
{{form-field/field-text content=content name=saveTo label=label key=key value=value width=width saveTo=saveTo multiple=multiple placeholder=placeholder}}
{{/if}}
// components / form-field / field-select / component.js
import Ember from 'ember';
export default Ember.Component.extend({
componentModel: function() {
return this.store.findAll(this.get('content'));
}.property(),
actions: {
componentQuery: function(query, deferred) {
this.store.query(this.get('content'), { [this.get('key')]: {contains:query.term}, limit:[this.get('setting.service.limit')]})
.then(deferred.resolve, deferred.reject);
}
}
});
// components / form-field / field-select / template.hbs
<label for="{{key}}">{{label}}</label>
{{input type="hidden" name=saveTo value=selectedValue}}
{{select-2 content=componentModel value=selectedValue optionLabelPath=key optionValuePath=value placeholder=placeholder multiple=multiple query="componentQuery"}}
我无法弄清楚如何将所选值传回给我的父母
同时,字段是通过数据库自动生成的,所以接下来我需要找出一种方法来传递对象中的值,我可以做一个foreach然后将值保存到数据库中。