简体   繁体   中英

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. 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.

http://emberjs.jsbin.com/nefas/6/edit

Few things with your jsbin.

  • this.store din not work as you have not mentioned your adapter like this

      App.ApplicationAdapter = DS.FixtureAdapter; 
  • You din not return in the model return .

Though you have got around what you wanted, I have made a jsbin that might have what you want. http://emberjs.jsbin.com/saxuy/1/edit

Update

http://emberjs.jsbin.com/saxuy/6/edit

You could set the url_type attribute of your url model directly like this in your template.

{{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.

Looks like your logic is working just fine

http://emberjs.jsbin.com/nefas/12/edit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM