I asked earlier why would it be that my model’s properties are empty when sent to my api (asp.net web api, and using the web-api adapter)
So I created a “test” model on both ends to test, a create route and submit my model. Actually it does work.
But when adding another class as property, it does not. So I’m guessing it’s either my naming conventions OR I did this custom component that render a select list wrong
apologies for posting tons of code, i just really dont know where to look no more .,…
fyi, when i post and hit the breakpoint in my api (correct api call) the name property (string) is set, the TestType property is null)
My web api models:
public class TestModel
{
public int Id { get; set; }
public string Name { get; set; }
public TestTypeModel TestType { get; set; }
}
public class TestTypeModel
{
public int Id { get; set; }
public string Name { get; set; }
}
My ember models (first “test.js”, then “testtype.js”)
export default Model.extend({
name: attr('string'),
testtype: belongsTo('testtype')
});
export default Model.extend({
name: attr('string'),
test: belongsTo('test')
});
My component (first “.js” then “.hbs”)
export default Ember.Component.extend({
tagName: 'select',
classNames: ['form-control'],
datatype: '',
items: [],
selectedId: 0,
store: Ember.inject.service(),
didReceiveAttrs : function(){
this._super(...arguments);
Ember.run.scheduleOnce('afterRender', this, this.afterRenderEvent);
},
afterRenderEvent : function(){
var store = this.get('store');
let items = store.findAll(this.get('datatype'));
this.set('items', items);
Ember.run.later(function() {
Ember.$('select').select2();
});
}
});
{{#each items as |item|}}
{{#if (eq selectedId item.id)}}
<option selected="selected" value="{{item.id}}">{{item.name}}</option>
{{else}}
<option value="{{item.id}}"> {{item.name}} </option>
{{/if}}
{{/each}}
and finally in my “create.js” template (in templates/test/create.js)
{{select-component datatype='testtype' }}
I just purchased "Ember Data in the wild, hopefully will get o understand this myself, but would appreciate any pointers …