mardi 20 octobre 2015

How to get a single record to the template from model in emberjs

I'm new to ember js. I was trying to get a single record from my mongo db database to the template for viewing that user's details.But it actually give me the all set of data in the model.what did i do wrong?

templates/profile.hbs

<h2>Welcome user</h2>

{{#each item in model}}

{{item.userName}}

{{/each}}

routes/profile.hbs

 import Ember from 'ember';

export default Ember.Route.extend({

model: function() {
        return this.store.find('user',{userName:'sanka'});
    }

});

router.js

Router.map(function() {
  this.route('login', {});
  this.route('about', {});
  this.route('register', {});
  this.route('profile', {});
});

models/user.js

import DS from 'ember-data';

export default DS.Model.extend({


    docType:DS.attr('string'),
    firstName:DS.attr('string'),


    userName:DS.attr('string'),
    password:DS.attr('string'),

    lastName:DS.attr('string'),
    mobileNo:DS.attr('string'),
    landNo:DS.attr('string'),
    address:DS.attr(
        {
        no:'string',
        street:'string',
        city:'string'
    }
    ),

    nicNo:DS.attr('string'),
    permissionList:DS.hasMany('permission'),
    created_at:DS.attr('date'),
    updated_at:DS.attr('date')

}); 




Aucun commentaire:

Enregistrer un commentaire