samedi 31 octobre 2015

Data store return only one record in ember

I'm trying to view user list in a template.But it retrieves only one(last) record i have entered.Why is it returning a single record? Is it a data-store cache problem?Following is the approach that i have followed

templates/userlist.hbs

{{#each item in model}}
{{#link-to 'userlist.edit' item.id}}edit:{{item.userName}}{{/link-to}}
{{/each}}

routes/userlist.js

    import Ember from 'ember';

    export default Ember.Route.extend({

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

    });

model/user.js

import DS from 'ember-data';

export default DS.Model.extend({


    docType:DS.attr('string'),
    firstName:DS.attr('string'),
    role: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'),



}); 

api/user.js

module.exports.getAllUsers=function(req,res) {
    UserModel.find({},function(err,docs) {
        if(err) {
            res.send({error:err});
        }
        else {
            res.send({user:docs});
        }
    });
};

app/routes.js

router.route('/api/users').get(function(req,res){users.getAllUsers(req,res)})
                              .post(function(req,res){console.log(req.body);users.addUser(req,res);});




Aucun commentaire:

Enregistrer un commentaire