What is the method for combining two SC.RecordArray instances in Sproutcore?

Below is the code snippet :

        queryTree = SC.Query.local('Tree.Category',
        "categoryId = {categoryId}", {
            categoryId: this.get('guid'),
            orderBy: "name ASC"
        });
        queryNote = SC.Query.local('Tree.Note',
            "categoryId = {categoryId}", {
            categoryId: this.get('guid'),
            orderBy: "name ASC"
        });
        var arrayCategory = Tree.store.find(queryTree);
        var arrayNote = Tree.store.find(queryNote);
        //Combine arrayCategory and arrayNote

I am trying to create a new array of records by merging the data from arrayCategory and arrayNote. I checked the documentation, but I couldn't find a direct concatenate function for this purpose.

Answer №1

This solution should work perfectly:

let data = Tree.store.find(SC.Query.local([Tree.Category, Tree.Note],
  "categoryId = {categoryId}", {
  categoryId: this.get('guid'),
  orderBy: "name ASC"
}));

When trying to concatenate two arrays, the pushObjects method can be used. However, this method will not function with the result of an SC.Query since it returns an SC.RecordArray that cannot be manually edited (as it automatically updates when records are added or removed).

Answer №2

Instead of concatenating the two search results, I found a solution by creating a field called isChild for each record in Tree.Note and Tree.Category. This field is set as YES in the former and NO in the latter.

return Tree.store.find(SC.Query.local(['Tree.Category','Tree.Note'],
        "categoryId = {categoryId}", {
            categoryId: this.get('guid'),
            orderBy: 'isChild, name',

        }))

EDIT : Despite this solution, there seems to be an ongoing issue. Any suggestions on how to improve this?

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

Display a block by using the focus() method

My objective is : To display a popin when the user clicks on a button To hide the popin when the user clicks elsewhere I previously implemented this solution successfully: Use jQuery to hide a DIV when the user clicks outside of it However, I wanted to ...

Interacting with a C# Web Service Using JQuery

I've set up a JSON web service in C# and I'm working on creating a custom HTML page to interact with it. http://localhost:25524/DBService.svc/json/db=TestDB/query=none When I input this URL into my browser, I expect to receive JSON formatted da ...

Using jQuery to append content with a variable as the source

Recently delving into jQuery and encountering an issue with getting my variable inside src when using append. Either it's not functional at all, or just displaying the variable name in string form in the console. Here is the code causing trouble: va ...

I am encountering an issue where the results I am expecting to see are not appearing

I am currently in the process of creating a form that utilizes some event handling functions. Below are the functions responsible for handling events within my form: const [name, setUsername] = useState(""); const [age, setAge] = useState(""); const ...

What could be the reason for the failure of Angular Material Table 2 selection model?

A Question about Angular Mat Table 2 Selection Model Why does the selection model in Angular Mat Table 2 fail when using a duplicate object with its select() or toggle() methods? Sharing Debugging Insights : Delve into my debugging process to understand ...

What is the best way to style MUI's Button component with a link to appear like a standard button?

I have a Button that allows users to download a file with a specific filename. Here is the code I used: <Button color='primary' href=`/apiproxy/objects/${id}/subobjects` LinkComponent={React.forwardRef((props, ref) => <Link {...pro ...

Navigating within two containers using the anchorScroll feature in AngularJS

I am trying to create a page with two columns of fixed height. The content in each column is generated using ng-repeat directive. Is it possible to implement scrolling within each column to a specific id using AngularJS? Code <div> Scroll to a p ...

Tips for automatically inserting a "read more" link once text exceeds a certain character count

Currently utilizing an open-source code to fetch Google reviews, but facing an issue with long reviews. They are messing up the layout of my site. I need to limit the characters displayed for each review and provide an option for users to read the full rev ...

Is it necessary to include a back button when navigating through paginated tables?

Within my AngularJS application, I have implemented pagination on the user list page. This allows me to retrieve ten users at a time from the server, with each click loading another set of ten users on a new page. The user details are presented in a tabl ...

Exporting JSON data as an Excel file in AngularJS, including the option to customize the fonts used for the

Currently, I am working on a project where I need to convert JSON data to an Excel file using JavaScript in combination with AngularJS. So far, I have successfully converted the JSON data to CSV format. However, I faced issues with maintaining the font s ...

What is the best way to ensure that the buttons remain in place once they have been clicked to reveal a drop-down menu?

Is there a way to keep 3 buttons inline and prevent them from moving when clicked to open a submenu? Changing their positions results in them stacking on top of each other. Any help or suggestions would be greatly appreciated, thank you! Here is the code ...

What is the best way to pass values between JSP Expression Language and Javascript?

I have a request object with the following content: List<Integer> list What is the best way to loop through this list using JavaScript? I am interested in obtaining the values of each element within the list. Note that these list values are not cu ...

Error: Unable to access undefined properties (reading 'url')

I am currently working on creating a drag-and-drop card game and I have encountered an issue with the react-dnd library. When using data from the file, everything works fine, but if I have to fetch the data externally, it throws an error. This problem see ...

Tips for producing/reserving cropped images from a photo? (includes converting images to base64 format)

https://i.sstatic.net/6Nath.png Imagine having two square datasets taggedImages: { 0: {id:0, left:100, top:100, thumbSize:100, type: 'A', seasons: ['All', 'All']}, 1: {id:1, left:200, top:200, thumbSize:100, type: &apos ...

Encounter a snag when attempting to upgrade to React version 16.10.2 while working with Ant Design Components - the error message reads: "

After upgrading to the latest React version 16.10.2, I encountered issues while using Ant Design Components. I specifically wanted to utilize the Title component from Typography. Here is an example of what I was trying to do: import { Typography } from & ...

Can you explain the functionality of isolate scope in angularjs?

I'm having trouble grasping the concept of scope : {}. Here's a snippet of code I've been working on. Why does it always display "strength" in the console instead of the actual array value? // Code goes here var app = angular.module("super ...

Adaptable Semantic UI form design

Welcome, internet friends! If anyone out there has a moment to spare and is familiar with Semantic UI, I could really use some assistance... Currently, I am working on a form that looks great on larger screens like this: https://i.stack.imgur.com/cafc5.j ...

What is the best way to redirect a URL to include www using Node.js?

What is the best way to redirect a URL to start with www? For instance: ---> ...

Error: SQL cannot read the JSON object provided in Java due to invalid JSON syntax

I'm encountering an issue while inputting JSON data into an SQL table (data type: json). The error message indicates that something is incorrect, but I am struggling to identify the specific issue. The JSON data I am attempting to insert: '{"{& ...

Obtain a transformed mesh that has been displaced using a displacementMap within three.js

Seeking to extract and export the mesh affected by a displacementMap. The displacement of vertexes is determined by this line in the shader (taken from three.js/src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl): transformed += normalize(obje ...