Best practices for assigning values to model field in EXT JS are as follows:

I'm facing an issue with a certain model structure:

Ext.define('my.workspace.Area', {
    extend: 'Ext.data.Model',
    idProperty: 'id',
    fields: [
        {name: 'id', type: 'string'},
        {name: 'width', type: 'int',getterName:'getWidth',setterName:'setWidth'},
        {name: 'height', type: 'int',getterName:'getHeight',setterName:'setHeight'}
    ]
});

When I create an instance of this model like so:

var area = Ext.create('my.workspace.Area');

I encounter a problem where I cannot utilize the setWidth and setHeight setters to assign values. Instead, I have to use it in this manner:

area.set('width', someWidthValue);
area.set('height', someHeightValue);

The issue arises when I try to serialize this object to json through a save() or sync() call on the containing store. The resulting JSON includes an unwanted "data" entity as shown below:

...
"area": {
      "data": {
        "id": "someId",
        "width": 260,
        "height": 502
      },
...

What I actually need is a clean structure without the extra "data" nesting. Could this be happening due to how I'm setting field values? If not, what is the correct approach to handle this situation?

Your insights and guidance are greatly appreciated.

Answer №1

While I'm not an expert in this field, I believe the following link may be of assistance:


From my understanding, the [data] plays a role within the structure of [Ext.data.Model] that you are extending.
The fields can be accessed through the [data].

area.set('width', someWidthValue);
area.get('width');

If you wish to utilize setters like setWidth, they can be defined as outlined in the provided link above.

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

Deactivating the ajax function is one of the key features of the Framework

I recently attempted to transition my app from plain HTML to framework 7, and while most things were running smoothly, I ran into a roadblock when it came to ajax requests. They simply wouldn't execute, resulting in an error message. Uncaught TypeErro ...

Exploring AngularJS: Leveraging ng-model within a custom directive featuring iterations and dynamically generated HTML elements

Trying to implement a directive for a grid, I encountered an issue where passing in a column definition that includes an HTML control with ng-model and ng-click directives resulted in an error: "Error: [$rootScope:infdig] 10 $digest() iterations reached. ...

What is the most efficient way to organize these arrays?

I've been racking my brain trying to figure out a sorting logic for some arrays, but I'm stumped. Maybe you have an idea? Imagine we have an array of objects structured like this: let obj = {day:'2', month:'6', year:'19 ...

What is the mechanism behind the functionality of bufferedReader() in Kotlin?

Currently, I am working on an Android project where I need to extract data from a .json file. My approach involves the following code snippet: val file = context.assets.open("myfile.json").bufferedReader().readText() Executing this code successfully retr ...

The controller is referencing $rootScope which has not been properly defined

Here is my understanding of the controller concept. Whenever I launch the application, an error message appears saying "$rootScope is not defined." Can someone provide assistance in identifying the issue? var webadmin = angular.module('PcPortal' ...

A simple guide on how to surround every incorrect input index in mapped inputs with red borders

I am incorporating a modal that corresponds each element of the object newCompanies to a specific row: {newCompanies.map((company, index) => { return ( <div> <div className="side- ...

A guide to displaying the properties of a JSON document

Can someone assist me in extracting only the country data from the information fetched through this API call? Many thanks! import requests import json url = "https://randomuser.me/api/" data = requests.get(url).json() print(data) ...

Add the onclick() functionality to a personalized Angular 4 directive

I'm facing an issue with accessing the style of a button in my directive. I want to add a margin-left property to the button using an onclick() function in the directive. However, it doesn't seem to be working. Strangely, setting the CSS from the ...

"Exploring the Application of Post Parameters in REST Services

I am in the process of setting up rest services for posting data. I was wondering if it's more efficient to post data using http form elements or to send all the data as one json string and parse it on the server side. Is there a preferred method or a ...

Can an AJAX request continue running even after the user has moved to a different page within the website?

Currently on my website, users are able to submit a form using ajax. The response, indicating whether the form was successfully submitted or if there was an issue, is displayed in an alert message. However, due to the asynchronous nature of this process, i ...

Can you guide me on how to access an Angular route using a URL that includes query parameters?

Within my current development project, I have implemented a user profile route that dynamically navigates based on the user's _id. This means that when a user accesses the page, their _id is stored in localStorage and then used to query MongoDB for th ...

vm.property compared to this.property

Although it may seem like a simple question, I am in need of some clarification. Currently, I have vuejs running on a single page of my website. The vm app is running in the footer script of the page without utilizing an app.js file or templates/components ...

Switching between multiple images using Jquery on a click event

Hi there, I am currently working on a project where I need to use jQuery to switch between three images when clicked. Once the third image is clicked, it should cycle back to the first picture. I was wondering if there is a way to modify the code below so ...

What is the best way to locate the closest element using JavaScript?

Is there a way to locate the closest object to the mouse pointer on a webpage? I have a hypothesis that involves utilizing the array function, however, I am uncertain if that is the correct approach. Furthermore, I lack knowledge of which specific proper ...

JavaScript middleware not detected

Currently, I have begun self-learning and encountered a roadblock that I can't seem to overcome. I am attempting to design a login page and delving into middleware for the first time. The error message I'm facing is: throw new TypeError('a ...

In Express.js, what is the best way to redirect to a specific route after sending a response to the client side?

As a beginner learning Express.JS, I am facing an issue with redirecting routes. My goal is to display a message to the user saying "Your data has been registered successfully." and then redirect them back to the form page after a certain time period. Howe ...

New data field is created with AngularFire2 update instead of updating existing field

I am facing an issue with updating a Firestore model in Angular 6. The model consists of a profile name and a list of hashtags. The "name" is stored as the value of a document field, while the "hashtags" are stored as keys in an object. However, every time ...

Updating an array using `setState` does not result in the array being updated

I created a component that uses the .map() method to render an array of students and has a button to shuffle and update the display. However, I'm facing an issue where the display does not update every time I click the button. const Home: NextPage = ...

By utilizing // within the source of a <script>, one can efficiently reference external files without specifying the

Curious if anyone has come across any evidence, proof, or firsthand accounts of utilizing the traditional http/https JavaScript <script> hack: <script src="//someserver.com/js/script.js"></script> Have you faced any problems with this m ...

Certain public files in Express cannot be accessed locally

While running my Node.js application on localhost, I am able to access http://localhost:3000/css/dashboard.css without any issues. However, when attempting to access http://localhost:3000/css/logo.png for a logo image in the same directory, all I receive i ...