add/delete items from Ember Data backed ArrayController

前端 未结 4 761
旧时难觅i
旧时难觅i 2021-01-18 01:59

I\'m using an ArrayController in my application that is fed from a Ember Data REST call via the application\'s Router:

postsController.connectOutlet(\'commen         


        
4条回答
  •  逝去的感伤
    2021-01-18 02:39

    A comment will be too long...

    I don't know how do you try to add a record, but you can try to do this: App.Comment.createRecord({}). If all goes right, it will update automatically your controller content. (I think the result of App.Comment.find() works as a 'live' array, and when creating a record, it's automatically updated) Here is how we do this in our app:

    App.ProjectsRoute = Ember.Route.extend({
      route: 'projects',
    
      collection: Ember.Route.extend({
        route: '/',
    
        connectOutlets: function (router) {
          router.get('applicationController').connectOutlet({
            name: 'projects',
            context: App.Project.find()
          });
        }
     })
    

    and then, the handler of creating a project (in the router):

    createProject: function (router) {
      App.Project.createRecord({
        name: 'new project name'.loc()
      });
      router.get('store').commit();
    },
    

提交回复
热议问题