ember.js - Emberjs adding objects to ArrayController, server query is immutable -
i'm trying add objects emberjs arraycontroller. have "create" action fires when button pushed. works fine can't seem add element this.pushobject function arraycontroller. error message:
uncaught error: result of server query (on app.software) immutable. i guess because i'm using restadapter load data , not i'm adding elements manually?
here controller , create action.
app.softwareindexcontroller = ember.arraycontroller.extend({ sortproperties: ['revision'], create:function(){ var revision = $('#software_revision').val(); var doc = $('#software_document').val(); var software = app.software.createrecord({ product_id: 1, revision: revision, doc: doc }); this.pushobject(software); } }); here route
app.softwareindexroute = ember.route.extend({ setupcontroller:function(controller){ var product_id = 1; controller.set('content', app.software.find({product_id:1})); } }); here model , store
app.store = ds.store.extend({ revision: 12, adapter: 'ds.restadapter' }); ds.restadapter.configure("plurals", { software: "software" }); app.software = ds.model.extend({ revision: ds.attr('string'), doc: ds.attr('string'), verified: ds.attr('boolean') }); and here template view create form , list of software
<script type="text/x-handlebars" data-template-name="software/index"> <p> <fieldset> <legend>create new software revision</legend> <label for="software_revision">revision</label> <input id="software_revision" name="software_revision" type="text" placeholder=""> <label for="software_document">document id</label> <input id="software_document" name="software_document" type="text" placeholder=""> <button class="btn btn-success" {{action create}}>create</button> </fieldset> </p> {{#if length}} <table class="table"> <thead> <tr> <th>revision</th> <th>created</th> </tr> </thead> <tbody> {{#each controller}} <tr> <td>{{revision}}</td> <td>{{createdat}}</td> </tr> {{/each}} </tbody> </table> {{else}} <div class="alert alert-info"> <button type="button" class="close" data-dismiss="alert">×</button> <strong>no software revisions found!</strong> start creating new revision above. </div> {{/if}} </script> does know proper way add new object arraycontroller store? thank you!
this works way if change route doesn't use restadapter
app.softwareindexroute = ember.route.extend({ setupcontroller:function(controller){ var product_id = 1; controller.set('content', []); // not using restadapter load data } });
i had same problem. looks content returned app.software.find() immutable array. able around getting content of immutable array returned mutable array.
for example:
in ember 1.0.0 + ember data 1.0.0 beta 3:
this.store.find('software').then(function (softwares) { controller.set('content', softwares.get('content')); }); and guess version working @ time of post:
controller.set('content', app.software.find().get('content'));
Comments
Post a Comment