Selects, promises, ember-data and I'm crazy


#1

Hello Everyone,

Since I start developing with Ember, I’ve got problems with select, usually I solve it with something, but Today I found my problem, and now I don’t know what is the best solution.

The problem is:

I define call the view select with that:

{{view "select" value=model.parent
		selection=model.parent
		optionLabelPath='content.path_name'
		optionValuePath='content'
		content=listGroups
		prompt="Select group"
		class="form-control"}}

And I’ve got the list of elements for the view using a this.store.find… like that:

listGroups: function (){
	return this.store.find('group');
}.property(),

My problem is: when emberJS show the view, It loads parent.model, when it see that parent.model is non existing on listGroups because it doesn’t exist, it changes or ignores (I don’t know exacly, because the changes don’t appear on other views) and when the listGroups load, it don’t know the correct value.

Now, I made a variable that is idGroup, and put value=idGroup, etc… But I don’t know if it’s the best solution.

Thanks!

Edit: Sorry, You can look one of my projects that I’ve got this problem in https://github.com/Dracks/password-manager-emberjs/ (I change a little things on the code for the post, but it’s based on https://github.com/Dracks/password-manager-emberjs/blob/master/app/controllers/group/edit.js and https://github.com/Dracks/password-manager-emberjs/blob/master/app/templates/group/edit.hbs#L3-L10 )


#2

The select view doesn’t play nicely with promises unfortunately.

I’ve solved this in the past by resolving the promise in the route on the model hook (i.e. the model is a hash, of which one attribute is the resolved listGroups.) Then the template can pass the resolved listGroups directly into the select.


#3

Thank you!

Yesterday I was playing with select view all the day, and I found that the last version of Ember, works better with promises, but with old versions, I should take the list and found the object inside the list to put on selection, like this:

selected_language: function (){
    var language=this.get('model.language.id');
    if (language!=null){
        language = this.get('language_list').find(function (e){
            return e.get('id')==language;
        });
    } else {
        language= this.get('language_list.0');
    }
    return language;
}.property('model.language', 'language_list.content')

Thanks!