jeudi 26 mai 2016

Cannot access what model() hook is returning in controller

i'm quite new to ember and new to Web developement in general.

I'm trying to redirect to a page through an action "Browse" which compares input Title and Keyword with the ones from a "Theme" from the database(Firebase). If they match I can see my page, if they don't I'll throw an error.

Index.hbs

 <div class="jumbotron">
    <div class="container">
    <form>
      <div class="form-group">
        <label for="inputTheme">Theme</label>
    
      </div>
          <div class="form-group">
        <label for="inputKeyword">Password</label>
        
      </div>
    <button class='btn btn-info' >Browse</button>
    </form>
      </div>
    </div>

index.js (Controller)

import Ember from 'ember';

export default Ember.Controller.extend({
  isDisabled: true,

  inputTheme: '',
  inputKeyword: '',    

  actions: {
    browse() {
        this.transitionToRoute("/themes/:theme_id/browse");
    }

  }
});

index.js (Route)

import Ember from 'ember';

export default Ember.Route.extend({
    model()
    {
        this.store.query('theme', {
        orderBy: 'title',
        equalTo: this.get('inputTitle')
      }).then(function(data) {
        return data.get('firstObject');
      });

    }
});

Router.js

import Ember from 'ember';
import config from './config/environment';

const Router = Ember.Router.extend({
  location: config.locationType
});

Router.map(function() {
  this.route('about');
  this.route('contact');
  this.route('browse', { path: '/themes/:theme_id/browse'});


  this.route('admin', function() {
    this.route('contacts');
  });

  this.route('themes', function() {
    this.route('new');
    this.route('edit', { path: '/:theme_id/edit'});
    this.route('browse', { path: '/:theme_id/browse'});
  });
});

export default Router;

Theme.js (model)

import Ember from 'ember';
import Model from 'ember-data/model';
import attr from 'ember-data/attr';

export default Model.extend({
  title: attr('string'),
  keyword: attr('string'),
  master: attr('string'),
  description: attr('string'),

});

The thing is :

1) I don't have any access to "inputTitle" from the route so I can't Query dynamically. Though when I do it the hard way it gets what I need.

2) When I try to access model from my controller it says that there's nothing in it.

What did I miss ?




Aucun commentaire:

Enregistrer un commentaire