Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I modified your JSbin <a href="http://jsbin.com/ucanam/1975/" rel="nofollow">http://jsbin.com/ucanam/1975/</a> </p> <p>If you want to persist records you must create them in the store with <strong>createRecord()</strong> and then <strong>save()</strong> them. The new newLink function</p> <pre><code> newLink: function() { var store = this.get("store"), linkName = this.get("linkName"), linkUrl = this.get("linkUrl"), links = this.get("links"), selectedLabels = this.get('selectedLabels'); if(selectedLabels.get('length') &gt; 0) { if(linkName.length &gt; 0 &amp;&amp; linkUrl.length &gt; 0) { var newLink = store.createRecord('link', { name: linkName, url: linkUrl }); selectedLabels.forEach(function(label){ newLink.get('labels').addObject(label); }); newLink.save().then(function(link){ links.addObject(link); }); this.set("linkName", ""); this.set("linkUrl", ""); } } else { alert("You have to select a label!"); } }, </code></pre> <p>For <strong>deleting records</strong> there are <strong>problems using forEach</strong> because <strong>the result of a find to the store is a live array</strong>. You can see this discussion in GitHub <a href="https://github.com/emberjs/data/issues/772" rel="nofollow">https://github.com/emberjs/data/issues/772</a>. So your remove label function should be (note the use of <strong>toArray()</strong> to make a static copy of the live array)</p> <pre><code> remove: function() { var indexController = this.get('controllers.index'), label = this.get('model'), linksPromise = this.get('store').find('link'); linksPromise.then(function(links){ links.toArray().forEach(function(link){ var linkLabels = link.get('labels'), linkLabelsIds = linkLabels.mapProperty('id'); if(linkLabelsIds.contains(label.get("id"))) { if(linkLabelsIds.get("length") == 1) { console.log("delete link: "+link.get("name")); indexController.get("links").removeObject(link); link.deleteRecord(); link.save(); } } }); label.deleteRecord(); label.save(); }); } </code></pre> <p>Final note, don't forget to make a <strong>save()</strong> on the records after deleting them, jsBin here: <a href="http://jsbin.com/ucanam/1989/" rel="nofollow">http://jsbin.com/ucanam/1989/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload