[英]Ember.js: how to set associated model via select box
My app has two models Url and UrlType and I want to select UrlType via select box. 我的应用有两个模型Url和UrlType,我想通过选择框选择UrlType。 How do I do that?
我怎么做? Here is the jsbin where I tried to reproduce the scenario, though this.get('store') do not work :( But the idea must be pretty clear.
这是我试图重现该场景的jsbin,尽管this.get('store')不起作用:(但是这个主意必须很清楚。
http://emberjs.jsbin.com/nefas/6/edit http://emberjs.jsbin.com/nefas/6/edit
Few things with your jsbin. 用您的jsbin几件事。
this.store
din not work as you have not mentioned your adapter like this this.store
din不起作用,因为您没有像这样提到适配器
App.ApplicationAdapter = DS.FixtureAdapter;
You din not return in the model return
. 您不会在模型
return
。
Though you have got around what you wanted, I have made a jsbin that might have what you want. 尽管您已经了解了想要的东西,但是我制作了一个可能具有您想要的东西的jsbin。 http://emberjs.jsbin.com/saxuy/1/edit
http://emberjs.jsbin.com/saxuy/1/edit
http://emberjs.jsbin.com/saxuy/6/edit http://emberjs.jsbin.com/saxuy/6/edit
You could set the url_type
attribute of your url model directly like this in your template. 您可以像这样在模板中直接设置url模型的
url_type
属性。
{{view Ember.Select content=urlTypes optionLabelPath='content.caption' selection=url_type}}
If there was a url_type
set for the model, it will be the selected option. 如果为模型设置了
url_type
,它将是所选选项。
Looks like your logic is working just fine 看起来您的逻辑工作正常
http://emberjs.jsbin.com/nefas/12/edit http://emberjs.jsbin.com/nefas/12/edit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.