The value retrieved from the JavaScript Object data is not accurate

Currently immersed in a JavaScript project utilizing Sencha, I've encountered an issue that has me completely stumped.

The problem seems straightforward. Behold my code snippet:

console.log("store : ");
console.log(store);
console.log("store length :");
console.log(store.data.length);

And this is the result it yields:

store :
_data: Ext.apply.create.Class
_model: ()
_modelDefaults: Ext.Object.classify.objectClass
_params: Ext.Object.classify.objectClass
_proxy: Ext.apply.create.Class
_remoteFilter: false
_remoteGroup: false
_remoteSort: false
_storeId: "Indicator_Value"
_syncRemovedRecords: false
config: Ext.Object.classify.objectClass
data: Ext.apply.create.Class
     _autoFilter: true
    _autoSort: true
    _filterRoot: "data"
    _sortRoot: "data"
    all: Array[2]
    config: Ext.Object.classify.objectClass
    dirtyIndices: false
    getKey: (record)
    indices: Object
    initConfig: ()
    initialConfig: Object
    items: Array[2]
    keys: Array[2]
    length: 2
map: Object
__proto__: Ext.util.Collection#constructor
dateFirst: Mon Aug 31 2015 14:47:36 GMT+0200 (Paris, Madrid (heure d’été))
dateLast: Mon Aug 31 2015 15:02:48 GMT+0200 (Paris, Madrid (heure d’été))
emptyNext: false
emptyPrevious: false
eventDispatcher: Ext.apply.create.Class
getEventDispatcher: ()
getId: ()
getObservableId: ()
getUniqueId: ()
graphType: 1
id: "myapp-store-indicator_value-1"
indicatorId: 262
initConfig: ()
initialConfig: Object
initialized: true
managedListeners: Object
observableId: "#myapp-store-indicator_value-1"
period: "H"
removed: Array[0]
titleIndicatorValue: "Duration in FTC"
usedSelectors: Array[1]
__proto__: Object


store length :
14

I'm at a loss. According to logic, store.data.length should be 2, yet it consistently shows 14. Could it be that there's some fundamental concept about how stores function that eludes me? Any support would be immensely appreciated; I've been grappling with this for around 2 hours now, and I can't seem to find a way out.

Thank you!

Answer №1

I'm struggling to understand this. According to my code, store.data.length should be 2, but it consistently shows up as 14.

Here's the explanation: The number "2" represents the current count of items in the store when you access it directly. However, the number "14" reflects the count at the specific moment you write it to the console. It's likely that the count has changed between these two points in time!

You can easily replicate this scenario:

var store = Ext.create('Ext.data.Store', {
    data: ['foo', 'bar', 'aa', 'foo', 'bar', 'aa', 'foo', 'bar', 'aa', 'foo', 'bar', 'aa', 'bar', 'aa']
});
console.log(store);
console.log(store.data.length);
store.removeAt(0, 12);

Try this example yourself:

Answer №2

size is a JavaScript attribute, so it's not advisable to name your variable size.

If it belongs to a predefined class within this platform you're using, determine the specific size you need and attempt the following:

console.log(company.data.all.size);

Answer №3

The data property within the Ext.data.Store is not stored as an array, but rather as a MixedCollection. This MixedCollection does not contain a length property.

To accurately determine the number of records in the store, you should use

store.getCount()

Answer №4

If you're looking to access the data property in a data store, you can use the following code snippet:

store.data

The data type of store.data is Ext.util.MixedCollection, so you can determine its count using the following code:

store.data.getCount()

In addition to using console.log(store); to check for output, you can also achieve similar results with:

store.data.items.length

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

Acquiring matching values in list box by selecting a particular value from the dropdown menu

When selecting a value from a dropdown, I want the list box to populate accordingly. For instance, if I click on "obs" in the dropdown, I expect to see "brs1", "crs1", and "drs1" in the list box. [{ "name": "obs", "date": "1458834026000", "attr001": ...

PHP project encountered an error stating: "Uncaught TypeError: Ajax is not a function"

I am in the process of configuring an apache server for a project using XAMPP, MySQL, and PHP 5.6 Unfortunately, it appears that there is an issue with how JavaScript has been referenced in the project, and I am unable to get it to function correctly (th ...

Exploring Angular 2's nested formGroups, formArrays, and template binding benefits

Here's the issue at hand: I have a complex form with nested formgroups, visualized in a "simplified" structure like this: -> MyForm (formGroup) -> Whatever01 (formControl - input) -> Whatever02 (formControl - input) -> Whate ...

Variable used in jQuery/ajax click eventIncorporating a

Looking to build a basic webpage with jQuery/Ajax functionality? I have 3 buttons, each performing an ajax call to retrieve different files from the server. The buttons are differentiated by their class names and the files they request. However, all other ...

Having trouble with React Router v4 not displaying any content?

I have checked multiple sources for help, such as [here][1] and [here][2], but I am still facing issues. I am using react-router version 4, however, when I try to run the console, nothing shows up on my page. It seems like my headerContainer is not being r ...

Change the text inside a container without losing any associated event listeners using JavaScript or jQuery

Here is the HTML code: <div id="div001"> This is ${Row.1}. <p>${Row.2} explain something else.</p> <p>${Row.3} welcome you. <span>${Hello.World}, this is a new world.</span></p> </div> My objective is ...

Problem encountered while trying to publish a post using Iron Router

I'm encountering some difficulties when trying to create a route that allows me to respond to comments (.../comments/:_id/reply) and publish the related post. Below is the code snippet: Publications Meteor.publish('commentUser', function(c ...

Enhancing HTML through Angular 7 with HTTP responses

Sorry to bother you with this question, but I could really use some help. I'm facing an issue with updating the innerHTML or text of a specific HTML div based on data from an observable. When I try to access the element's content using .innerHTM ...

Filter a Vue list based on a checkbox that can be either checked or unchecked

I am currently working on my Vue app and aiming to filter a list to display only entries that have been moderated. However, I am encountering an issue where when the checkbox is checked, I receive all the results that are true, and when the checkbox is un ...

Why is my MongoDB $match aggregation query not returning results within a specified date range?

I have been struggling with a MongoDB aggregation query that is not returning any results, just an empty array. It seems like the issue lies in how it's processing the date range. Oddly enough, when I use PriceHourly.find({ date: { $lt: end, $gt: sta ...

Enhance your coding experience with Firebase Autocomplete on VScode

Recently, I installed VScode along with the necessary packages for JavaScript development. As I started writing code involving Firebase, I noticed that the autocomplete feature, which worked perfectly fine in Xcode, was not functioning in VScode. How can I ...

The iron-session package does not export the path ./next/dist from the package

I am encountering an issue while using iron-session. Below is the code snippet causing the error: import { withIronSessionSsr } from 'iron-session/next/dist'; ... export const getServerSideProps = withIronSessionSsr(async function ({ req, r ...

Activate a particular panel within the leftPanel using PDFNet Webviewer

When using disableElements in the setQuickBarPanelContents() function, I am able to remove 2 of the 3 panels from the leftPanel: setQuickBarPanelContents() { this.instance.disableElements(['notesPanel', 'notesPanelButton', &apos ...

Receiving a reply from the axios function

Whenever I try to call the lookUpItem function from ItemSearch.vue, I always get an undefined response. Code snippet from ItemSearch.vue: <script setup lang="ts"> import { lookUpItem } from '../systemApi' async fu ...

Passing a parameter from a redirect function to an onClick in React using TypeScript

I am facing a challenge in passing a parameter to my redirectSingleLocker function. This function is intended to take me to the detailed page of a specific locker, identified by a guid. The lockerData.map method is used to display all the JSON data in a ta ...

Pop-up website opening with fixed dimensions error

On my webpage, I have a terminal where you can type commands and receive output. For example, typing "/unsolvedproblems" displays a list of unsolved problems with a hyperlink. I've been trying to make the hyperlink open in a popup window with a fixed ...

Synchronize data with Microsoft AJAX using force sync

When working with the Microsoft AJAX framework, I encounter a problem where my AJAX calls are asynchronous when I actually need them to be synchronous. I'm struggling to find a solution for this issue. In addition, I have been having difficulty findi ...

Struggling with the paste event glitch on Opera versions 11 and under

I have been experimenting with this simple code that is designed to transfer focus to another text box when a right-click is detected on the first one, allowing any subsequent paste event to paste the text into the second box: <!DOCTYPE html> <ht ...

Objection.js - Relationship with intermediate table

I'm currently struggling to grasp the concept of modeling many-to-many relationships in objects.js. In my app, I have three tables: Users, Games, and UsersScore. Each user can have a score in a game. The structure of the tables is as follows: USERS ...

The absence of defined exports in TypeScript has presented a challenge, despite attempting various improvement methods

I've exhausted all available resources on the web regarding the TypeScript export issues, but none seem to resolve the problem. Watching a tutorial on YouTube, the presenter faced no such obstacles as I am encountering now. After updating the tsconf ...