使用Ember,我正在尝试构建一个表单,并在商店中填充<select>
个下拉列表。我不知道如何从这里恢复一个值,以便在&#34; save&#34;功能
我做错了什么?
以下是我所拥有的简化版本:
route
访问不同模型。这很好用:
import Ember from 'ember';
export default Ember.Route.extend({
model() {
var store = this.store;
return Ember.RSVP.hash({
fighters: store.findAll('fighter'),
duels:store.findAll('duel')
});
},
setupController(controller, models) {
var fighters = models.fighters;
var duels = models.duels;
controller.set('fighters', fighters);
controller.set('duels', duels);
}
});
Controller应使用表单的值保存新的决斗。这里&#34; formdata&#34;表单提交时为null
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
save(formdata) {
var newduel = this.store.createRecord('duel', {
fighter1:formdata.fighter1,
fighter2:formdata.fighter2,
});
}
}
});
模板显示下拉列表确定,但我无法连接&#34;到控制器中的值,无论我尝试##FIGHTERn##
!
<form {{action "save" formdata on "submit"}}>
<dl>
<dt>
<select value='##FIGHTER1##'>
{{#each fighters as |fighter|}}
<option value={{fighter.id}}>{{fighter.name}}</option>
{{/each}}
</select>
</dt>
<dt>
<select value=##FIGHTER2##>
{{#each fighters as |fighter|}}
<option value={{fighter.id}}>{{fighter.name}}</option>
{{/each}}
</select>
</dt>
</dl>
<button type="submit">Add</button>
答案 0 :(得分:3)
AsyncLayoutInflater inflater = new AsyncLayoutInflater(getActivity());
do {
inflater.inflate(R.layout.xxx, gridLayout, new AsyncLayoutInflater.OnInflateFinishedListener() {
public void onInflateFinished(View view, int resid, ViewGroup parent) {
//some logic
parent.addView(view);
Log.d(TAG, parent.getChildCount() + " " + parent.getWidth() + "x" + parent.getHeight());
}
});
} while (cursor.moveToNext());
控制器:
<form {{action "save" formdata on "submit"}}>
<dl>
<dt>
<select onchange={{action (mut fighter1) value="target.value"}}>
{{#each fighters as |fighter|}}
<option value={{fighter.id}} selected={{is-equal fighter1 fighter.id}}>{{fighter.name}}</option>
{{/each}}
</select>
</dt>
<dt>
<select onchange={{action (mut fighter2) value="target.value"}}>
{{#each fighters as |fighter|}}
<option value={{fighter.id}} selected={{is-equal fighter2 fighter.id}}>{{fighter.name}}</option>
{{/each}}
</select>
</dt>
</dl>
<button type="submit">Add</button>
这可以帮到你