backbone.js using external .json file as data source - ajax

I have a basic app http://jsfiddle.net/p3hpZ/ which uses data hardcoded in the script.js file like so:
//model data
var things = [
{ title: "Macbook Air", price: 799, id: 1 },
{ title: "Macbook Pro", price: 999, id: 2 },
{ title: "The new iPad", price: 399, id: 3 },
{ title: "Magic Mouse", price: 50, id: 4 },
{ title: "Cinema Display", price: 799, id: 5 }
];
I am trying to work out how to move the data into a seperate .json file. Here is what I have so far http://jsfiddle.net/wVsZh/

Related

Not getting products data from the Array of nested object using react.js. error- products.filter is no a function in categoryPreview component

const SHOP_DATA = [
{
title: 'Hats',
items: [
{
id: 1,
name: 'Brown Brim',
imageUrl: 'https://i.ibb.co/ZYW3VTp/brown-brim.png',
price: 25,
},
{
id: 2,
name: 'Blue Beanie',
imageUrl: 'https://i.ibb.co/ypkgK0X/blue-beanie.png',
price: 18,
},
{
id: 3,
name: 'Brown Cowboy',
imageUrl: 'https://i.ibb.co/QdJwgmp/brown-cowboy.png',
price: 35,
},
{
id: 4,
name: 'Grey Brim',
imageUrl: 'https://i.ibb.co/RjBLWxB/grey-brim.png',
price: 25,
},
{
id: 5,
name: 'Green Beanie',
imageUrl: 'https://i.ibb.co/YTjW3vF/green-beanie.png',
price: 18,
},
{
id: 6,
name: 'Palm Tree Cap',
imageUrl: 'https://i.ibb.co/rKBDvJX/palm-tree-cap.png',
price: 14,
},
{
id: 7,
name: 'Red Beanie',
imageUrl: 'https://i.ibb.co/bLB646Z/red-beanie.png',
price: 18,
},
{
id: 8,
name: 'Wolf Cap',
imageUrl: 'https://i.ibb.co/1f2nWMM/wolf-cap.png',
price: 14,
},
{
id: 9,
name: 'Blue Snapback',
imageUrl: 'https://i.ibb.co/X2VJP2W/blue-snapback.png',
price: 16,
},
],
},
{
title: 'Sneakers',
items: [
{
id: 10,
name: 'Adidas NMD',
imageUrl: 'https://i.ibb.co/0s3pdnc/adidas-nmd.png',
price: 220,
},
{
id: 11,
name: 'Adidas Yeezy',
imageUrl: 'https://i.ibb.co/dJbG1cT/yeezy.png',
price: 280,
},
{
id: 12,
name: 'Black Converse',
imageUrl: 'https://i.ibb.co/bPmVXyP/black-converse.png',
price: 110,
},
{
id: 13,
name: 'Nike White AirForce',
imageUrl: 'https://i.ibb.co/1RcFPk0/white-nike-high-tops.png',
price: 160,
},
{
id: 14,
name: 'Nike Red High Tops',
imageUrl: 'https://i.ibb.co/QcvzydB/nikes-red.png',
price: 160,
},
{
id: 15,
name: 'Nike Brown High Tops',
imageUrl: 'https://i.ibb.co/fMTV342/nike-brown.png',
price: 160,
},
{
id: 16,
name: 'Air Jordan Limited',
imageUrl: 'https://i.ibb.co/w4k6Ws9/nike-funky.png',
price: 190,
},
{
id: 17,
name: 'Timberlands',
imageUrl: 'https://i.ibb.co/Mhh6wBg/timberlands.png',
price: 200,
},
],
},
]
export default SHOP_DATA;
const UiUxCategories = () => {
return (
<div>
{
Object.keys(SHOP_DATA).map((key) => {
const products = SHOP_DATA[key];
return (
<CategoryPreview key={key} title={key} products={products} />
)
})
}
</div>
)
}
error- products.filter is no a function in categoryPreview component
const CategoryPreview = ({ title, products }) => {
return (
<div >
<h2>{title}</h2>
<div>
{products
.filter((_, idx) => idx < 4)
.map((product) => (
<ProductCard key={product.id} product={product} />
))}
</div>
</div>
);
}

Filter data with duplicate record in kendoTreeList

In KendoJqueryTreelist, when filter data using Contains then duplicate record is not show
In KendoJqueryTreelist, when filter data using Contains then duplicate record is not show, But i require to show all record that contains(Including duplicate record) in kendo jquery treelist. filter by last name
"<script>
$("#treeList1").kendoTreeList({
columns: [
"lastName",
"position"
],
filterable: true,
dataSource: {
data: [
{ id: 1, parentId: null, lastName: "Jackson", position: "CEO" },
{ id: 2, parentId: 1, lastName: "Weber", position: " VP, Engineering" },
{ id: 1, parentId: null, lastName: "Jackson", position: "CEO" },
{ id: 4, parentId: 1, lastName: "Weber", position: " VP, Engineering" }
]
}
});
</script>"
Telerik/Kendo never likes to have duplicate id's breaks almost all of their components, I would on the server side generate a unique id for every row and add a new column if "employee-id" is used:
$("#treeList1").kendoTreeList({
columns: [
"lastName",
"position"
],
filterable: true,
dataSource: {
data: [
{ id:1, employeeId: 1, parentId: null, lastName: "Jackson", position: "CEO" },
{ id:2, employeeId: 2, parentId: 1, lastName: "Weber", position: " VP, Engineering" },
{ id:3, employeeId: 1, parentId: null, lastName: "Jackson", position: "CEO" },
{ id:4, employeeId: 4, parentId: 1, lastName: "Weber", position: " VP, Engineering" }
]
}
});
</script>"

ReferenceField and ReferenceInput

(Sorry for my English. It will be great if you correct my mistakes).
I have a list of products and create product / edit product pages.
Each product has a set of attributes.
Each set of attributes has attributes.
How to do next:
When i choose a set of attributes for product at creating or at editing, in the form (create product / edit product) will be added new TextInputs with labels of attributes.
Here is my products:
products: [
{
id: 1,
title: 'title1',
description: 'description1',
shortDescription: 'shortDescription1',
seo: {
title: 'seotitle1',
description: 'description1',
keywords: ['keywords1'],
},
price: 428,
parentCategories: [1],
images: [
{
id: 123,
url: 'urlImage1',
title: 'urlTitle1',
},
],
isItActive: true,
creationDate: '2008-04-01T14:57:42.105Z',
modificationDate: '2009-04-01T14:57:42.105Z',
setOfAttributes: 1,
}, {
id: 2,
title: 'title2',
description: 'description2',
shortDescription: 'shortDescription2',
seo: {
title: 'seotitle2',
description: 'description2',
keywords: ['keywords2'],
},
price: 418,
parentCategories: [2],
images: [
{
id: 122,
url: 'urlImage2',
title: 'urlTitle2',
},
],
isItActive: false,
creationDate: '2010-04-01T14:57:42.105Z',
modificationDate: '2011-04-01T14:57:42.105Z',
setOfAttributes: 3,
}, {
id: 3,
title: 'title3',
description: 'description3',
shortDescription: 'shortDescription3',
seo: {
title: 'seotitle3',
description: 'description3',
keywords: ['keywords3'],
},
price: 423,
parentCategories: [3],
images: [
{
id: 323,
url: 'urlImage3',
title: 'urlTitle3',
},
],
isItActive: true,
creationDate: '2012-04-01T14:57:42.105Z',
modificationDate: '2013-04-01T14:57:42.105Z',
setOfAttributes: 2,
},
],
Here is my attrubutes:
attributes: [
{
id: 1,
name: 'asdgsd',
title: 'qwed',
type: 'список',
showInFilter: null,
},
{
id: 2,
name: 'zxcv',
title: 'fkf',
type: 'текстовое поле',
showInFilter: null,
},
{
id: 3,
name: 'asdkd',
title: 'rczh',
type: null,
showInFilter: null,
},
],
Here is a set of attributes:
setOfAttributes: [
{
id: 1,
title: 'Набор 1',
attributes: [1, 3],
},
{
id: 2,
title: 'Набор 2',
attributes: [3, 1, 2],
},
{
id: 3,
title: 'Набор 3',
attributes: [2, 3],
},
],
I was able to do just that(productsEdit.jsx):
<ReferenceField source="setOfAttributes" reference="setOfAttributes" linkType={false}>
<ReferenceArrayField source="attributes" reference="attributes">
<SingleFieldList>
<ChipField source="title" />
</SingleFieldList>
</ReferenceArrayField>
</ReferenceField>

Normalizing a nested entity that shares the current schema

My goal is to normalize this object:
{
talks: [
{
id: 1755,
speakers: [
{
id: 1487,
name: 'John Doe',
},
],
related_talks: [{
id: 14,
speakers: [{
id: 125,
name: 'Jane Doe',
}],
event: {
id: 181,
name: 'First Annual',
},
}],
event: {
id: 180,
name: 'July Party',
},
},
],
};
into this result:
{
entities: {
events: {
181: {
id: 181,
name: 'First Annual'
},
180: {
id: 180,
name: 'July Party'
}
},
speakers: {
125: {
id: 125,
name: 'Jane Doe'
},
1487: {
id: 1487,
name: 'John Doe'
}
},
talks: {
1755: {
id: 1755,
event: 181,
speakers: [ 1487 ],
related_talks: [ 14 ],
},
14: {
id: 14,
speakers: [ 125 ],
event: 180,
}
},
},
result: {
talks: [ 1755, 14 ],
},
}
If you'll notice, the items in related_talks are treated the same as a talk.
My schemas follow the examples and are set up like this:
const speaker = new schema.Entity('speakers');
const event = new schema.Entity('events');
export const talk = new schema.Entity('talks', {
speakers: [speaker],
event,
});
talk.define({ related_talks: [talk] });
No matter what I try, I can't get the items in related_talks to be added to the result.talks array. It is, however, in the entities object.
What is my schema configuration missing in order to accommodate this?
Unfortunately, if this is your requirement, Normalizr is not for you. Alternatively, if you're looking for a list of "talks" by ID, you can use Object.keys(data.entities.talks)

Adding multiple series to Chart

I'm currently trying to build a chart showing number of downloads of a product per date.
A sample of the current code is as follows:
var downloads = [
{ value: 48, date: new Date("2013/11/01") },
{ value: 50, date: new Date("2013/11/02") },
{ value: 55, date: new Date("2013/11/03") },
{ value: 35, date: new Date("2013/11/04") }
];
$("#chart").kendoChart({
dataSource: {
data: downloads
},
series: [{
type: "line",
aggregate: "avg",
field: "value",
categoryField: "date"
}],
categoryAxis: {
baseUnit: "days",
min: new Date("2013/10/31"),
max: new Date("2013/11/10"),
labels: {
dateFormats: {
days: "dd/MM"
}
}
}
});
It works fine if I have to display data for one product only. How would I proceed to display download data for another product, i.e. adding another series to the chart?
Right! I figured it out myself. Here it is:
$("#chart").kendoChart({
seriesDefaults: {
tooltip: {
visible: true,
},
type:"line",
aggregate:"avg",
field:"value",
categoryField:"date"
},
series: [{
name: "Product 1",
data: [{ value: 48, date: new Date("2013/11/01") }, { value: 50, date: new Date("2013/11/02") }]
},
{
name: "Product 2",
data: [{ value: 55, date: new Date("2013/11/03") }, { value: 35, date: new Date("2013/11/04") }]
}],
categoryAxis: {
baseUnit: "days",
min: new Date("2013/10/31"),
max: new Date("2013/11/10"),
labels: {
dateFormats: {
days: "dd/MM"
}
}
}
});

Resources