Ext Filter with special value - extjs

I have a Model A (include Model B). For example:
fields: [{
name: 'code',
type: 'string'
}]
hasMany: [{
name: 'modelB',
model: 'modelB'
}]
Model B:
fields: [{
name: 'code',
type: 'string'
}]
I want to add filter to Store A (mapping with Model A) by Model B's code. For example:
Data: {code: 'A001', modelB: [{code: 'B001'}, {code: 'B002'}]},
{code: 'A002', modelB: [{code: 'B001'}, {code: 'B003'}]},
{code: 'A003', modelB: [{code: 'B002'}]}
Query value: 'B002'
Expected result: 'A001' and 'A003'
I tried:
customFilter = Ext.create('Ext.util.Filter', {
property: 'modelB.code',
operation: '=',
value: '001' // <- Model B's code
});
storeA.addFilter(customFilter);
It's not working. Please help!

Related

unexpected token ",", expected expression in sanity studio vision

I am following a course on react native and We are using Sanity as our backend. I have already set the schemas and made the adjustments in my Sanity Studio.
HERE IS MY FEATURED SCHEMA CODE:
export default {
name: 'featured',
title: 'featured Menu Categories',
type: 'document',
fields: [
{
name: 'name',
type: 'string',
title: 'Featured category name',
validation: (Role) => Role.required(),
},
{
name: 'short_description',
type: 'string',
title: 'Short description',
validation: (Role) => Role.max(200),
},
{
name: 'restuarants',
type: 'array',
title: 'Restuarants',
of: [{ type: 'reference', to: [{ type: 'restuarant' }] }],
},
],
};
HERE IS MY RESTAURANT SCHEMA CODE:
export default {
name: 'restaurant',
title: 'Restuarant',
type: 'document',
fields: [
{
name: 'name',
type: 'string',
title: 'Restuarant name',
validation: (Role) => Role.required(),
},
{
name: 'short_description',
type: 'string',
title: 'Short description',
validation: (Role) => Role.max(200),
},
{
name: 'image',
type: 'image',
title: 'Image of the Restuarant',
},
{
name: 'lat',
type: 'number',
title: 'latitude of the restaurant',
},
{
name: 'long',
type: 'number',
title: 'longitude of the restaurant,
},
{
name: 'address',
type: 'string',
title: 'Address of the Restuarant',
validation: (Role) => Role.required(),
},
{
name: 'rating',
type: 'number',
title: 'Enter a rating of (1 - 5)',
validation: (Role) =>
Role.required()
.min(1)
.max(5)
.error('please enter a number between 1 - 5'),
},
{
name: 'type',
type: 'string',
title: 'Category',
validation: (Role) => Role.required(),
type: 'reference',
to: [{ type: 'category' }],
},
{
name: 'dishes',
type: 'array',
title: 'Dishes',
of: [{ type: 'reference', to: [{ type: 'dish' }] }],
},
],
};
I also did one for the dish and category.
Then I went to my Sanity Studio to fill in my restaurant schema fields;
After I went to my Vision Board in Sanity Studio and did a query(Just like the instructor):
*[_type == "featured"]{
...,
restuarants[]=> {
...,
dishes[]=> ,
type=> {
name
}
},
}
And I got an error of:
unexpected token ",", expected expression ;
I did what any developer would have done if they got an error. I double-checked my code and compared it to the instructor in the video. (I still got the error). Then I googled it(And found no answer). It's been 2 days now and I still haven't found anything.
This is my first querying in Sanity and I am not sure what I am doing wrong with my query. Can anyone please help me? Thanks.
As the error mentioned, you missed a ' in your schema code.
Keep a ' after restaurant
{
name: 'long',
type: 'number',
title: 'longitude of the restaurant',
},
No worries I found the answer to my problem. The problem was with my querying.
HERE WAS MY CODE BEFORE:
*[_type == "featured"]{
...,
restuarants[]=> {
...,
dishes[]=> ,
type=> {
name
}
},
}
THIS IS HOW I WAS SUPPOSED TO WRITE IT:
*[_type == "featured"]{
...,
restuarants[]-> {
...,
dishes[] -> ,
type-> {
name
}
},
}
I was supposed to use a straight line instead of an equal sign.
I hope this helps anyone who runs into this problem

How to upload dynamic data from a store that comes from a json

I would like to upload data from a store that has the following characteristics:
has two fields 'YEAR' and 'SALES'
a proxy that via url connects to a json
the data is set inline with the data property
Here is the model code:
Ext.define('DashboardClienti.model.ChartFatturato', {
extend: 'Ext.data.Model',
alias: 'model.chartfatturato',
identifier: 'negative',
fields: [
{
name: 'ANNO_0',
type: 'int'
},{
name: 'ANNO_1',
type: 'int'
},{
name: 'ANNO_2',
type: 'int'
},{
name: 'FATTURATO_TOT_ANNO_0',
type: 'float'
},{
name: 'FATTURATO_TOT_ANNO_1',
type: 'float'
},{
name: 'FATTURATO_TOT_ANNO_2',
type: 'float'
}],
});
Here is the store code:
Ext.define('DashboardClienti.store.ChartFatturato', {
extend: 'Ext.data.Store',
alias: 'store.chartfatturato',
storeId: 'chartfatturatoStore',
model: 'DashboardClienti.model.ChartFatturato',
fields: ['ANNO','FATTURATO'],
data: [
{ ANNO: 'ANNO_0', FATTURATO: 'FATTURATO_TOT_ANNO_0' },
{ ANNO: 'ANNO_1', FATTURATO: 'FATTURATO_TOT_ANNO_0' },
{ ANNO: 'ANNO_2', FATTURATO: 'FATTURATO_TOT_ANNO_0' }
],
proxy: {
type: 'ajax',
url : AppConstants.UrlCustomersDetail,
method : 'GET',
reader: {
type: 'json'
},
writer: {
type: 'json'
},
/*extraParams: {
format: 'json'
}
*/
}
});
From the proxy that takes data from a json I get this data:
ANNO_0: 2021
ANNO_1: 2020
ANNO_2: 2019
CAP: "32021"
CITTA: "AGORDO"
CODICE: "1010"
CODICE_FISCALE: "0000000000"
EMAIL: "johndoe#gmail.com"
FATTURATO_PER_ANNO_0: 0
FATTURATO_PER_ANNO_1: 1321.84
FATTURATO_PER_ANNO_2: 3058.25
FATTURATO_TOT_ANNO_0: 0
FATTURATO_TOT_ANNO_1: 3426.71
FATTURATO_TOT_ANNO_2: 5274.32
FRAZIONE: ""
ID: 40832
ID_1: 7594
ID_2: 0
ID_AGENTE: 0
ID_CAPOAREA: 0
ID_CLIENTE: 40832
ID_CLIENTE_1: 0
ID_DITTA: 1
INDIRIZZO: "PIAZZA LIBERTÀ, 17-18"
NAZIONE: "IT"
PARTITA_IVA: "000000000"
PERIODO_AL: "2021-06-30T00:00:00.000Z"
PERSONA_RIFERIMENTO_1: ""
PERSONA_RIFERIMENTO_2: ""
.....
I would like to know how to load the data from the proxy in the DATA property of the store because the YEAR AND SALES fields are not filled in with the proxy values.

creating nested structure with backbone-relational

I'm trying to create a three cascading dropdown lists. First one constains projects, second contains tasks for selected project and the last one sites for selected task.
I want to use the Backbone-Relational plugin, but have hard time to create the proper relations. That's my first time with this plugin.
Code so far:
App.Models.ProjectItem = Backbone.RelationalModel.extend({
default: {
id: 0,
name: ''
},
relations: [{
type: Backbone.HasMany,
key: 'tasks',
relatedModel: App.Models.TaskItem,
//includeInJSON: Backbone.Model.prototype.idAttribute,
collectionType: App.Collections.TasksCollection,
reverseRelation: {
key: 'projectId',
//includeInJSON: Backbone.Model.prototype.idAttribute,
type: Backbone.HasOne
}
}]
});
App.Collections.ProjectsCollection = Backbone.Collection.extend({
model: App.Models.ProjectItem
});
App.Models.TaskItem = Backbone.RelationalModel.extend({
default: {
id: 0,
name: ''
},
relations: [{
type: Backbone.HasMany,
key: 'sites',
relatedModel: App.Models.SiteItem,
includeInJSON: Backbone.Model.prototype.idAttribute,
collectionType: App.Collections.SitesCollection,
reverseRelation: {
key: 'taskId',
//includeInJSON: Backbone.Model.prototype.idAttribute,
type: Backbone.HasOne
}
}]
});
App.Collections.TasksCollection = Backbone.Collection.extend({
model: App.Models.TaskItem
});
App.Models.SiteItem = Backbone.RelationalModel.extend({
default: {
id: 0,
name: ''
}
});
App.Collections.SitesCollection = Backbone.Collection.extend({
model: App.Models.SiteItem
});
Creating single project:
var item = new App.Models.ProjectItem({
id: 1,
name: 'project',
tasks: [
{
id: 1,
name: 'task',
sites: [
{
id: 1,
name: 'site'
}
]
}
]
})
This object serialized to json looks like this:
"{"id":1,"name":"task","tasks":[1],"sites":[{"id":1,"name":"site"}],"projectId":null}"
My questions:
1) Why the sites array is not nested in the tasks one?
2) Sites collection is not serialized the same way that tasks one is. Should I create a relations in the site model too?
3) Why the projectId is returned for the root?
After many hours of trials and errors I finally got it. The order matters..
Working code:
App.Models.SiteItem = Backbone.RelationalModel.extend({
default: {
siteId: 0,
name: ''
}
});
App.Collections.SitesCollection = Backbone.Collection.extend({
model: App.Models.SiteItem
});
App.Models.TaskItem = Backbone.RelationalModel.extend({
default: {
taskId: 0,
name: ''
},
relations: [{
type: Backbone.HasMany,
key: 'sites',
relatedModel: App.Models.SiteItem,
//includeInJSON: Backbone.Model.prototype.idAttribute,
collectionType: App.Collections.SitesCollection,
reverseRelation: {
key: 'task',
includeInJSON: 'taskId',
type: Backbone.HasOne
}
}]
});
App.Collections.TasksCollection = Backbone.Collection.extend({
model: App.Models.TaskItem
});
App.Models.ProjectItem = Backbone.RelationalModel.extend({
default: {
projectId: 0,
name: ''
},
relations: [{
type: Backbone.HasMany,
key: 'tasks',
relatedModel: App.Models.TaskItem,
// includeInJSON: 'taskId',
collectionType: App.Collections.TasksCollection,
reverseRelation: {
key: 'project',
includeInJSON: 'projectId',
type: Backbone.HasOne
}
}]
});
App.Collections.ProjectsCollection = Backbone.Collection.extend({
model: App.Models.ProjectItem
});
For sample data:
var item = new App.Models.ProjectItem({
projectId: 2,
name: 'first',
tasks: [
{
taskId: 1,
name: 'task',
sites:[{siteId:1, name: 'site'}]
}
]
});
I got this json string:
"{"projectId":2,"name":"first","tasks":[{"taskId":1,"name":"task","sites":[{"siteId":1,"name":"site","task":1}],"project":2}]}"

ExtJS - Store proxy loading data using Array Reader

I am having problems loading an array of data from an external file into my store.
This is the file containing the data:
/data/contacts
[
["Lisa", "lisa#hotmail.com", "555-222-3333"],
["Bart", "bart#hotmail.com", "555-222-3333"],
["Homer", "homer#hotmail.com", "555-222-3333"],
["Marge", "marge#hotmail.com", "555-222-3333"]
]
This is my store:
Ext.define('MyApp.store.Contacts', {
extend: 'Ext.data.Store',
autoLoad: true,
alias: 'store.contacts',
model: 'MyApp.model.Contact',
proxy: {
type: 'ajax',
reader: {
type: 'array'
},
url: '../data/contacts'
}
});
This is my model:
Ext.define('MyApp.model.Contact', {
extend: 'Ext.data.Model',
alias: 'model.contact',
fields: [
{name: 'name', mapping: 0},
{name: 'email', mapping: 1},
{name: 'phone', mapping: 2},
]
});
And I am getting this error:
[E] Ext.JSON.decode(): You're trying to decode an invalid JSON String: [
["Lisa", "lisa#hotmail.com", "555-222-3333"],
["Bart", "bart#hotmail.com", "555-222-3333"],
["Homer", "homer#hotmail.com", "555-222-3333"],
["Marge", "marge#hotmail.com", "555-222-3333"]
]
Does anyone have any suggestions on what I am doing wrong, or what I should do? Preferably I do not want to change the format of the array in the data file.
Okay, I realized what I did wrong. It was a very stupid user error made by me.
In my data file: /data/contacts, what I really had was this:
[
["Lisa", "lisa#hotmail.com", "555-222-3333"],
["Bart", "bart#hotmail.com", "555-222-3333"],
["Homer", "homer#hotmail.com", "555-222-3333"],
["Marge", "marge#hotmail.com", "555-222-3333"]
]
// [
// {name: 'Lisa', email: 'lisa#simpsons.com', phone: '555-222-1212'},
// {name: 'Bart', email: 'bart#simpsons.com', phone: '555-333-2212'},
// {name: 'Homer', email: 'homer#simpsons.com', phone: '555-122-1212'},
// {name: 'Marge', email: 'marge#simpsons.com', phone: '555-123-1212'}
// ]
I was previously testing other options for my JSON format, and I was silly enough to think that I could place comment //'s in a normal file.
Removing the comments from the file will fix the error. The array defined in this file can now be loaded into the store.
The error message says that the received JSON is invalid. You can check the validity online at http://jsonlint.com. If it is invalid it is the first thing to fix.
Then, I see the combination of ajax proxy and array reader for the first time in many years with Ext and I'm not sure it is supported.

OrderBy with enumerable property in AngularJS

I have an object array where every object can have an array of properties, like this
[
{
name: 'Big house',
properties: [{name: 'Area',value: '400'}, {name: 'Year',value: '1950'}]
},
{
name: 'Small house',
properties: [{name: 'Area',value: '400'}, {name: 'Year',value: '1950'}]
},
{
name: 'Green house',
properties: [{name: 'Area',value: '40'}, {name: 'Year',value: '2008'}]
},
{
name: 'Red house',
properties: [{name: 'Area',value: '250'}, {name: 'Year',value: '1999'}]
},
];
Now I'd like to order this list by one of the properties, say Area, using a filter in ng-repeat. Is that possible?
I've been play around with this in plunker (http://plnkr.co/edit/GEgLxv5zJyW0ZBTtJR5S?p=preview) but cannot figure out how to do.
Thanks in advance
This will work if the area is always the first property:
<tr ng-repeat="house in houses | orderBy:'properties[0].value'">
Also make sure that the area is defined as an integer, right now they are strings. So 250 will be sorted before 40.
So remove the quotes from the numbers:
{
name: 'Area',
value: 400
}
, {
name: 'Year',
value: '1950'
}

Resources