logo
down
shadow

Ember.js - Return unicode character from computed property


Ember.js - Return unicode character from computed property

By : saad
Date : November 25 2020, 07:27 PM
hop of those help? I just created a simple jsbin: http://jsbin.com/izurix/5/edit
Basically doing this does not return any & for me:
code :


Share : facebook icon twitter icon
Ember.js binding to computed property in Ember.Object from controller doesn't work

Ember.js binding to computed property in Ember.Object from controller doesn't work


By : nicholweyand
Date : March 29 2020, 07:55 AM
this will help You're currently binding the totalBoth variable to the class definition and not an instance of a class, which just wont work. What you want to do is observe for changes in any of the instances.
Check out this updated JSBin: http://jsbin.com/cuqitufo/6/edit
code :
totalBoth   : function(){
  var total = 0;
  App.TypeNumbers.forEach(function(item){
    console.log( item.get('calculatedTotal') );
    total += item.get('calculatedTotal');
  });
  return total;
}.property( 'App.TypeNumbers.@each.calculatedTotal' ),
Ember Computed Property Listener ceases to function after first successful return

Ember Computed Property Listener ceases to function after first successful return


By : user3124065
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , NEVER MIND. It's right there in the code. On a successful ajax code, I'm reassigning searchResults to a static array, no longer a function.
Returning won't work out of a .then, however, so I still need a workaround for returning the data. For that, I will add a more traditional Ember event listener to call my 'search' function which will reset the property of 'searchResults'
code :
    {{input type="text" value=searchText placeholder="Search for users..." action=search on='change'}}

<ul>
  {{#each user in searchResults}}
    <li>{{user.Handle}}</li>
    {{else}}
    <p>No users found.</p>
  {{/each}}
</ul>
App.AutocompleteController = Ember.Controller.extend({
searchText: null,
search: function () {
    var searchText = this.get('searchText');
    var data = { 'searchTerm' : searchText };
    var self = this;
    if (!searchText) { return; }
    if (searchText.length < 2) { return; }
    else {
    $.get('/searchUsers', data).then(function (response) {
            self.set("searchResults", JSON.parse(response));
        }); //end then
    }
}.property('searchText')
return first element from array as computed property from Ember controller subclass

return first element from array as computed property from Ember controller subclass


By : user3797331
Date : March 29 2020, 07:55 AM
help you fix your problem This would work.
Long way (just to improve your computed property code):
code :
// controller work.js
import Ember from "ember";
export default Ember.Controller.extend({
  firstElement: function () {
    return this.get('model').get('firstObject'); // or this.get('model.firstObject'); 
  }.property('model.[]')
});
// works = ... as is
export default Ember.Route.extend({
  model: function() {
    return works;
  }
});
//template works
{{model.firstObject}} {{!-- first object of model array --}}
{{model.firstObject.name}}  {{!-- name of first object --}}
{{#liquid-with model as currentModel}}
  {{currentModel.firstObject.name}}
{{/liquid-with}}
How to return Ajax data inside Ember computed property

How to return Ajax data inside Ember computed property


By : Dan Nowak
Date : March 29 2020, 07:55 AM
like below fixes the issue In general, it is a bad practice to have ajax calls in a computed property -- try having it in your model in the route, and pass the data down to your component (or wherever you are using your options property). I see you are observing 'name' -- is there a reason you are doing that? Since the url seems to be the same no matter the name, it seems like you don't need the computed property at all. That said, a computed property always needs to return something. So the only way I can think of making this work would be to return the promise in the computed property and then use it somewhere else in your code - maybe another function, wait for it to resolve in there and then set the optionArray.
To reiterate, I feel like you should ask yourself if you really need this logic in a computed property or if you can do it in a route. If not a route, at least in a function or another hook. If you provide more context, I can maybe help you better.
Ember computed property to return first X number of items from list

Ember computed property to return first X number of items from list


By : László Novák
Date : March 29 2020, 07:55 AM
will help you I figured this out just as I was about to post it so I figured I'd answer it...
All I was missing was a @each in the computed property dependency. So it works as expected with this:
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org