Ember.Select view raising concerns about the value being passed in the system

I am currently working on an Ember.js (1.0.0) Application where I'm incorporating the Ember.Select view to display three task lists: inProgress, completed, and unassigned. Users have the ability to filter tasks based on their project. However, upon loading the route, I encounter errors from Ember about the type of value being passed:

Assertion failed: The value that #each loops over must be an Array. You passed projects.all

Uncaught TypeError: Object projects.all has no method 'addArrayObserver'

Uncaught Error: Something you did caused a view to re-render after it rendered but before it was inserted into the DOM.

I've spent considerable time trying different variations of the code below - there's definitely something simple that I seem to be missing. It can't possibly be this challenging to make such a basic component work correctly. Your guidance in setting me on the right path would be greatly appreciated.

As defined in my Route:

Bee.TasksIndexRoute = Bee.Auth.Route.extend
    setupController: (ctrl) ->
        # fetching tasks
        Bee.Auth.send
            url: Bee.endpoint "/tasks"
        .done (tasks) -> 
            ctrl.set "tasks.all", tasks
        # fetching projects
        Bee.Auth.send
            url: Bee.endpoint "/projects"
        .done (projects) -> 
            ctrl.set "projects.owned", projects.owned
            ctrl.set "projects.participating", projects.participating
            ctrl.set "projects.all", projects.owned.concat projects.participating

In my Controller:

Bee.TasksIndexController = Ember.ObjectController.extend
    project: null
    content:
        tasks: 
            all: []
            inProgress: []
            completed: []
            unassgined: []
    projects: 
        all: []
        owned: []
        participating: []
    visible: (->
        ctrl = @
        # filtering tasks            
    ).property "project"

The Template structure:

<script type="text/x-handlebars" id="tasks/index">
    <div class="center-pane">
        <div class="top_options">
            <div class="project_filter">
                <strong>Viewing: </strong>
                {{view Ember.Select
                   content=projects.all
                   optionValuePath='content._id'
                   optionLabelPath='content.title'
                   value=project
                   prompt='All Tasks'
                }}
            </div>
            <strong class="gold-gradient option_button">
                {{#link-to 'tasks.create' classNames='new_task'}}Create Task{{/link-to}}
            </strong>
        </div>
        <div class="col3">
            <div class="col-header in-progress light-gradient">
                <h3>In Progress</h3>
            </div>
            <div id="tasks_active_list">
                {{#if visible.inProgress.length}}
                    <ul>{{#each visible.inProgress}}{{view Bee.TaskListView}}{{/each}}</ul>
                {{else}}
                    <p class="no_projects">None</p>
                {{/if}}
            </div>
        </div>
        <div class="col3">
            <div class="col-header completed light-gradient">
                <h3>Completed</h3>
            </div>
            <div id="tasks_closed_list">
                {{#if visible.completed.length}}
                    <ul>{{#each visible.completed}}{{view Bee.TaskListView}}{{/each}}</ul>
                {{else}}
                    <p class="no_projects">None</p>
                {{/if}}
            </div>
        </div>
        <div class="col3">
            <div class="col-header unassigned light-gradient">
                <h3>Unassigned</h3>
            </div>
            <div id="tasks_unassigned_list">
                {{#if visible.unassigned.length}}
                    <ul>{{#each visible.unassigned}}{{view Bee.TaskListView}}{{/each}}</ul>
                {{else}}
                    <p class="no_projects">None</p>
                {{/if}}
            </div>
        </div>
    </div>
</script>

Your insights would be invaluable. I understand that the issue lies with Ember.Select, as using a straightforward <select> works fine. However, I need to utilize Ember.Select for binding the value to the project property on the TasksIndexController to trigger the visible function.

Answer №1

Consider initializing projects.all to null at the beginning. It's possible that Ember select might have trouble with the default array in the class.

Bee.TasksIndexController = Ember.ObjectController.extend
  project: null
    content:
      tasks: 
        all: []
        inProgress: []
        completed: []
        unassgined: []
  projects: 
    all: null
    owned: []
    participating: []
  visible: (->
    ctrl = @
    # filter tasks here            
  ).property "project"



setupController: (ctrl) ->
    # get tasks
    Bee.Auth.send
        url: Bee.endpoint "/tasks"
    .done (tasks) -> 
        ctrl.set "tasks.all", tasks
    # get projects
    Bee.Auth.send
        url: Bee.endpoint "/projects"
    .done (projects) -> 
        ctrl.set "projects.owned", projects.owned
        ctrl.set "projects.participating", projects.participating
        ctrl.set "projects.all", projects.owned.concat projects.participating

For a simpler example, you can check out:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I modify the return value of Node.js' REPL from underscore _ to a different symbol?

Another question worth exploring: Utilizing the Underscore module in Node.js Has anyone found a method to customize the variable that Node.js' REPL assigns as the last return value? For instance, altering it from _ to __ or $_ could simplify globaliz ...

A JavaScript regular expression for identifying IMDB URLs

Could someone please help me identify the issue with this JavaScript code? "http://www.imdb.com/title/tt2618986/".match("~http://(?:.*\.|.*)imdb.com/(?:t|T)itle(?:\?|/)(..\d+)~i"); I tested it here https://regex101.com/r/yT7bG4/1 and it wo ...

By setting up a keydown event listener, I am unable to inspect HTML elements by using the F-12 key shortcut in Chrome

Recently, I encountered an issue where adding a keydown event listener in my JavaScript code prevented F-12 from working properly. window.addEventListener("keydown", function (event) { if (event.defaultPrevented){ retu ...

Why is the AJAX-generated HTML not being refreshed in the DOM?

When I load HTML content via AJAX onto a div using Mootools 1.11 and squeezebox, everything works perfectly in Firefox. However, when I try to load it in Internet Explorer (tested on IE7), the code fails with an error message stating "'null' is n ...

Ways to determine if a dynamically generated script tag has been successfully executed

Recently, I've been experimenting with dynamically creating a script tag: var head = document.getElementsByTagName('head')[0]; var script = document.createElement('script'); script.type = 'text/javascript'; script.charse ...

Having difficulty retrieving cookie from fetch() response

Many times, the issue of fetching cookies from a SO response has been raised on sites like: fetch: Getting cookies from fetch response or Unable to set cookie in browser using request and express modules in NodeJS However, none of the solutions provide ...

What is the best way to retrieve data from the server using Props in React Router and Redux?

In my project, I am utilizing React Router, Redux, Redux Sagas, and antd components. My primary objective is to click on a cell within a table of items, navigate to the Details page for that specific item, and retrieve details from the server using the ID ...

Any property modified by an event handler will consistently appear in its original form

Every second, a simple function is called using setInterval, with the goal of determining mouse or keyboard activity. The variable that tracks the activity is updated, but it always remains set to 0 despite the fact that console.log statements are being e ...

Modal does not close

I am experiencing an issue with closing a modal. I have checked jQuery and everything seems to be working fine. Currently, I am using version 1.12.4 and have the following script tag in the head of my code: <script src="https://ajax.googleapis.com/aja ...

Is it an error to pass arguments using square brackets when requiring a node module?

Recently, I came across this piece of nodeJS code on a GitHub repository: var env = process.env.NODE_ENV || 'development' , config = require('./config/config')[env] , auth = require('./config/middlewares/authorization') , mon ...

Error message in Node.js and Express: Attempting to modify HTTP headers after they have already been sent to the

element, I have thoroughly analyzed various responses on StackOverflow and GitHub Issues to address my issue, but unfortunately, none of them have provided a solution for my specific problem. Below is the code snippet (bear in mind that some parts may be ...

An issue occurred during the project compilation using npm

My project installation process is giving me some trouble. Initially, when I run npm install, it successfully installs all the dependencies. However, when I proceed to execute npm run compile, I encounter an error. Below is the log file for a better under ...

Trouble locating DOM element in Angular's ngAfterViewInit()

Currently, I am attempting to target a specific menu item element within my navigation that has an active class applied to it. This is in order to implement some customized animations. export class NavComponent implements AfterViewInit { @ViewChild(&a ...

Cascade function with several parameters

I'm looking to utilize a cascade function with multiple parameters: // Cascade function (function ($) { $.fn.cascade = function (options) { var defaults = {}; var opts = $.extend(defaults, options); return this.each(functi ...

Using the PATCH method in Rails instead of POST

i have some code to display here <%= form_for @campaign, url: brands_campaign_path(@campaign), method: :patch, :html => {:multipart => true, :class => 'form-horizontal'} do |f| %> and it generates the following <form class ...

Incorporating a .json file into res.render to pass data

Is there a way to pass an object array similar to the one below into res.render? var DataArray = [ {"type": "c#", "script":"csharp script"}, {"type": "javascript", "script":"javascr ...

Creating interactive web pages with Vue.js by adding HTML elements dynamically upon button click

My goal is to enable the user to add new information to an existing set that will be passed on to Vue from JSON. Below is my HTML code consisting of a div element with the id objectiveArea that Vue will render, and a button for users to add more entries: ...

JavaScript - Delayed Text Appearance with Smooth Start

I want to create a landing page where the text appears with a slight delay - first, the first line should be displayed followed by the second line. Both lines should have an easing effect as they appear. Below is a screenshot of the section: https://i.sst ...

What is the best way to retrieve the data stored in a TD element within a TR row in an HTML table?

How can I retrieve the value of a clicked table cell? https://i.stack.imgur.com/HfXBK.png <table id="table" class="table" style="margin-right: auto; margin-left: auto" > <thead> <tr> <th>Request Number</th> ...

Having difficulty operating the development environment

Currently enrolled in a Udemy course and facing an issue with running a script. Attempting to execute the command npm run dev results in the following error message: npm ERR! code ELIFECYCLE npm ERR! errno 2 npm ERR! <a href="/cdn-cgi/l/email-protectio ...