ember.js

How to do dependency injection in Ember with Ember CLI?

江枫思渺然 提交于 2019-12-13 14:33:11
问题 First, I made a small Ember app without Ember CLI. I had this piece of code. window.MyApp = Ember.Application.create({ ready: function() { this.register('session:current', MyApp.SessionController, { singleton: true }); this.inject('controller', 'session', 'session:current'); } }); This worked. Then I decided to rewrite everything from scratch with Ember CLI. I edited the file app/app.js and added the ready hook just like in my previous version. var App = Ember.Application.extend({

Ember.js POST requests return 400 from the server (Grape API) but are stored successfully into local storage

假如想象 提交于 2019-12-13 14:30:55
问题 I've been trying to get a simple Ember.js application to post to a Grape API backend for hours now, but I cannot seem to get it to work. I know the API works because I can post new records to it through the Swagger documentation, and they are persisted. I know the API and Ember are talking just fine because I can get all records from the server and interact with them on the page, and I know that Ember is working fine in a vacuum because my records are persisted to local storage. However, I

Event delegation for target

老子叫甜甜 提交于 2019-12-13 14:14:29
问题 In the following code, my click events delegate and all three 'click' handlers in my view hierarchy get fired. However, I also want to fire 'edit' in my entire view hierarchy. 'edit' is simply the target of an element in my 'child' view. Template <script type="text/x-handlebars"> {{#view App.GrandparentView}} {{#view App.ParentView}} {{#view App.ChildView}} <span {{action "edit" target="view"}}>Click Me</span> {{/view}} {{/view}} {{/view}} </script> ​ JavaScript App.GrandparentView = Ember

Nested object in `DS.attr()` isn't affected by `DS.rollbackAttributes()`

五迷三道 提交于 2019-12-13 11:35:22
问题 I have a model User as follow: import DS from 'ember-data'; const { attr, Model } = DS; export default Model.extend({ name: attr("string"), properties: attr(), }); User.properties is intended to hold a JSON object. I am updating the model through a form (using ember-one-way-controls) as follow: {{one-way-textarea model.name update=(action (mut model.name))}} {{one-way-textarea model.properties.description update=(action (mut model.properties.description))}} I have a button allowing the user

history.back() not working in phonegap ios build

瘦欲@ 提交于 2019-12-13 11:04:26
问题 Creating a nice little phonegap build for ios at the moment, runs fine in the browser, however, when I compile it in Xcode and run in the simulator the history.back() I'm using doesn't work. I need the history.back() in order to create a back button on each page in the app. Does anyone know why this may be the case, or an alternative solution. More information: phonegap build using ember js 回答1: Yes, exactly. In several version iOS, Android ( old), history.back() seem not working. To fix it,

How is the a value of this in ember.js computed property defined? [duplicate]

给你一囗甜甜゛ 提交于 2019-12-13 08:27:08
问题 This question already has an answer here : babel is exporting “this” as undefined in ember computed property (1 answer) Closed 3 years ago . I am trying to understand why using function() inside a computed property works, but a fat arrow does not. Here is a class I created, and two definitions of computed properties, one passing in function() {} (foo) , and the other passing in () => {} bar. I included both styles being passed into an array forEach() also for reference (foo1, and bar1). Can

Ember Handlebars Iterate object and display key inside nested each helper

血红的双手。 提交于 2019-12-13 08:27:06
问题 I want to iterate and render some text in my Ember Handlebars template I have a JSON as below; (comes within item) "reas":{"Display Text 1":[null],"Display Text 2":[null]} I want to display the text (Display Text 1/Display Text 2) on UI i.e. keys of my object. So in my Ember Handlebars template, I do {{#each item in item.reas}} <tr> <td>{{item}}</td> </tr> {{/each}} Earlier I had also tried the {{@key} But I am unable to get the text. What am I doing wrong ? PS: Please remember that this is

Javascript access parameter inside custom sort function

倾然丶 夕夏残阳落幕 提交于 2019-12-13 08:15:50
问题 I have a custom sort function defined & call it as below; myArr.sort(this.sortArrayBy, key); sortArrayBy: function(a, b) { let param = this.get('sortKey'); //How do I get this value here ? cannot pass it as param OR even access via 'this' if (a.param < b.param) return -1; if (a.param > b.param) return 1; return 0; }, I want to pass an additional param inside that function. How do I get access to that class attribute ? P.S: This code is inside my Ember controller class 回答1: You could use a

Version compatible issue with ember-precompile, ember.js and handlebars.js

雨燕双飞 提交于 2019-12-13 08:09:49
问题 I cannot read the precompiled templates in my html. It is due to the version compatible issue of ember-precompile with ember.js and handlebars.js. My code goes like this: Included the below files. <script src="../js/libs/jquery-1.10.2.js"></script> <script src="../js/libs/handlebars-v1.3.0.js"></script> <script src="../js/libs/ember-1.2.0.js"></script> <script src="js/precompile.js"></script> <script src="js/precompile.app.js"></script> Reading my compiled template inside body tag. <div id=

Ember Js nested forms

六月ゝ 毕业季﹏ 提交于 2019-12-13 07:52:08
问题 Currently I have a form called a "form A", I've created a number of views for this form, an edit, create and list. I want to be able to create a form called "form B", that will pull through "form A's ID" as a parent ID. To enable me to have a list of all form B under a "form A" (essential a one to many relationship). So at the moment under my list for "form A" I have this link for each item: {{#link-to 'form-a.form-b.listing' form-a.id}} <!--Link to a controller --> <span class="btn btn