ember-data

How to detect and save relation change in Ember 2.13.0?

拥有回忆 提交于 2019-12-23 09:47:38
问题 I have documents list. Every document has client attribute defined by belongsTo . When user change client in one of documents i want to show in the counter how many documents are changed. And when user decide he will press "publish" button which will save documents client changes to api. DS.Model in ember 2.13 has parameters (https://emberjs.com/api/data/classes/DS.Model.html): hasDirtyAttributes, dirtyType Both of them does not react on belongsTo/HasMany changes by Ember design . I saw many

Ember.js: how to save a model

天大地大妈咪最大 提交于 2019-12-23 09:18:37
问题 From the ember docs its clear you should be able to save a dirty model var m = App.MyModel.find(10) ; ... m.set("firstName", "John") ; m.get("isDirty") ; // --> true Now, I don't know how to save, things like m.save() ; App.MyModel.save(m) ; //etc do not work. Any suggestions ? CHeers 回答1: EDIT: This is now out of date with Ember Data 1.0 beta and onwards, please refer to Bart's answer If you are using Ember-Data, you need to call commit() on the model's transaction. m.get('transaction')

Uncaught Error: Assertion Failed: You may not set `id` as an attribute on your model

删除回忆录丶 提交于 2019-12-23 08:55:31
问题 Entire error: Uncaught Error: Assertion Failed: You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: DS.attr('<type>')` from App.Plan Ember Model: App.Plan = DS.Model.extend({ id: DS.attr('number'), name: DS.attr('string'), period: DS.attr('number'), price: DS.attr('number') }); Data coming from REST API: {"plans":[{"id":1,"name":"Monthly subscription","period":1,"price":2}]} Question: How can I move around the above error ? 回答1: Just leave out the

(Un)marshall JSON with named root for Ember Data using Scala case class on Spray

早过忘川 提交于 2019-12-23 05:44:11
问题 I am writing a RESTful interface and I would like to marshall and unmarshall JSON ready for Ember Data. The wrinkle is that Ember Data wants the entity name and the two libraries I've tried, spray-json and json4s, don't appear to do this easily. Desired Ember Data format { "coursePhoto": { "photoId": 1 } } Current default format: {"photoId":15} This should come from a case class: case class CoursePhoto(photoId: Long) I did get it running with the following custom code: object

Allowing models to contain array of objects

穿精又带淫゛_ 提交于 2019-12-23 04:28:16
问题 Is it possible to have a model that contains an array of objects, without separating out those objects into having unique IDs? For example, I have a slide with multiple parameters that may come back from the API: slide: { "id": 1, "name": "stack-overflow-page", "type": "webpage" "parameters": [ {"key": "url", "value": "http://stackoverflow.com"}, {"key": "extension", "value": "/questions/ask"} ] } On my slide configuration page, I want to configure the slide and it's list of parameters. Since

Ember.js {{render}} helper model not correctly set

不羁的心 提交于 2019-12-23 04:14:14
问题 I ran in a strange issue. I have an Article template. Within the article template I call a {{render "category/new" category}} . However when saving the new Category trough an action the wrong model is used. When I change it to {{render "category/new" this}} it uses the Article model. When I leave the model part empty it does also not work. The Template : <script type="text/x-handlebars" data-template-name="article"> ((...)) {{render "category/new" category}} // calls the popup for adding a

EmberJs, changedAttributes() is not showing changes in the nested keys of a Hash attribute

ε祈祈猫儿з 提交于 2019-12-23 02:38:54
问题 The object is DS.Model: $E.toString() > "<reports-dashboard-client-app@model:report::ember596:914fc1b0-b14d-0133-bce2-68a86d03d830>" The attribute is a Hash: // app/models/report.js export default DS.Model.extend({ filters: DS.attr(), ... }); This is how it looks like now: $E.get('filters') > Object {__ember_meta__: Meta} > __ember_meta__: Meta > age_groups: (...) > get age_groups: GETTER_FUNCTION() > set age_groups: SETTER_FUNCTION(value) > genders: (...) > get genders: GETTER_FUNCTION() >

ember data no model was found for attribute name

一笑奈何 提交于 2019-12-23 02:36:21
问题 I have defined a model(app/models/job.js) import DS from 'ember-data'; export default DS.Model.extend({ status: DS.attr(), result: DS.attr() }); And I am trying to load it from the index controller(app/controllers/index.js) import Ember from 'ember'; export default Ember.Controller.extend({ productName: "", customerName: "", startDate: "", endDate: "", actions: { search: function() { let data = this.store.find("job", '9e5ce869-89b3-4bfc-a70f-034593c21eae'); return data; } } }); The HTTP

GET unconventional JSON with Ember-data

梦想的初衷 提交于 2019-12-23 02:29:24
问题 I am working with Ember 1.5.1 and Ember-data 1.0 beta and I am using the DS.RESTADAPTER CLASS. I have two models, let say Post and User . The server replies at a GET request with the following JSON { data: [ .... ] } data is an array of users or posts depending on the request. The RestAdapter is designed around the idea that the JSON exchanged with the server should be conventional, and it expects the JSON returned from your server should look like this { posts: [ .... ] } or { users: [ ....

Ember Data- createRecord in a hasMany relationship

天涯浪子 提交于 2019-12-23 01:59:13
问题 I am using Ember Data beta2 and I have a hasMany relationship set up. When creating a child record do I have to use pushObject on the parent's corresponding property? When looking at the documentation I get the impression that I need to correctly set the record's parent property and save it. This is how I do it: addPlugin: function() { //get the value var title = this.get('newPluginName'); if (!title.trim()) { return; } var plugin = { name: title, category: this.get('model'), url: '' }; var