访问和更新夹具 Ember JS

Access and Update a Fixture Ember JS

如何 update/edit IndexController 中的特定人员?

App.Person=DS.Model.extend({
        name:DS.attr('string'),
        iminus:DS.attr(),
        iplus:DS.attr()
    });

    App.Person.FIXTURES=[
        {
            id:1,
            name:'M',
            iminus:[{amount:50,pers:'A'}],
            iplus:[]
        },
        {
            id:2,
            name:'An',
            iminus:[{amount:20,pers:'Mo'}],
            iplus:[]
        }
    ];
    App.IndexRoute=Ember.Route.extend({
        model:function(){
            return this.store.findAll('person');
        }
    });
    App.IndexController=Ember.ArrayController.extend({
    actions:{
        createNew:function(){
            //Access and Update a person record based on name
        }
    }
    });

如何根据 IndexController 中的名称访问和更新人员记录

var App = Ember.Application.create();

App.FixtureAdapter = DS.FixtureAdapter.extend({
    queryFixtures: function (records, query, type) {
        return records.filter(function (record) {
            for (var key in query) {
                if (!query.hasOwnProperty(key)) {
                    continue;
                }
                var value = query[key];
                if (record[key] !== value) {
                    return false;
                }
            }
            return true;
        });
    }
});

App.ApplicationAdapter = App.FixtureAdapter;

App.Router.map(function () {

});


App.Person = DS.Model.extend({
    name: DS.attr('string'),
    iminus: DS.attr(),
    iplus: DS.attr()
});

App.Person.reopenClass({
    FIXTURES: [{
        id: 1,
        name: 'M',
        iminus: [{
            amount: 50,
            pers: 'A'
        }],
        iplus: []
    }, {
        id: 2,
        name: 'An',
        iminus: [{
            amount: 20,
            pers: 'Mo'
        }],
        iplus: []
    }]
});

App.IndexRoute = Ember.Route.extend({
    model: function () {
        return this.store.findAll('person');
    }
});

App.IndexController = Ember.ArrayController.extend({
    actions: {
        updatePerson: function (name) {
            var person;

            this.get('model').filter(function (model) {
                if (model.get('name') === name) {
                    person = model;
                }
            });

            var iminus = person.get('iminus');
            iminus.push({
                amount: 100,
                pers: 'Mo'
            });

            person.setProperties({
                iminus: iminus
            });

            person.save()
                .then(success)
                .catch (fail);

            function success(model) {
                alert('success');
            }

            function fail(error) {
               alert('fail');
            }

        }
    }
});

http://emberjs.jsbin.com/wamiminesi/1/edit?html,js,output