HTML / JSON / Javascript / AJAX - javascript

i've tried to display some things from JSON into a localhost site ( "market_hash_name" and "image") but its only printing me one out of about 43 results on the site but in the console its printing all the elements.
i've used the " document.getElementById " to display it on the html site.
my question is:
Is there any kind of loop i can use to display all the market_hash_names and image on the html site?
<html>
<head>
<title>Inventory</title>
</head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
$.ajax({
url: 'inventory.json',
dataType: 'json',
type: 'get',
contentType: "text/html; charset=UTF-8",
cache: false,
success: function(data){
$(data.data.steam_inventory.items).each(function(index, value){
var marketname = value.market_hash_name
var urlicon = value.image
document.getElementById("outputIconURL").src = urlicon
document.getElementById("outputName").innerHTML = marketname
console.log(marketname, "\n", urlicon)
});
}
});
</script>
<img id=outputIconURL width="350" height="300">
<p id=outputName></p>
</body>
</html>
here is the JSON File but only 100 out of 4000 lines of code. should be enough.
{
"status": "success",
"data": {
"app_id": "730",
"context_id": "2",
"steam_inventory": {
"status": "success",
"fresh_or_cached": "cached",
"total_items": 45,
"items": [
{
"app_id": "730",
"context_id": "2",
"number_of_items": 2,
"item_ids": [
"20276818150",
"20224634211"
],
"asset_ids": [
"20276818150",
"20224634211"
],
"class_id": "3761545285",
"instance_id": "0",
"market_hash_name": "Prisma 2 Case",
"suggested_price": "0.03",
"item_type": "Container",
"item_class": null,
"item_rarity": null,
"item_weapon": null,
"item_quality": "Base Grade",
"item_itemset": "The Prisma 2 Collection",
"image": "https://steamcommunity-a.akamaihd.net/economy/image/-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXU5A1PIYQNqhpOSV-fRPasw8rsUFJ5KBFZv668FFU1nfbOIj8W7oWzkYLdlPOsMOmIk2kGscAj2erE99Sn2AGw_0M4NW2hIYOLMlhpcmY0CRM/256fx256f",
"inspectable": false,
"inspect_link": null,
"phase": null,
"tags": {
"type": "Container",
"collection": "The Prisma 2 Collection",
"category": "Normal",
"quality": "Base Grade"
},
"has_buy_orders": false,
"recent_sales_info": null,
"stickers": null,
"fraud_warnings": [
[],
[]
],
"is_listing_allowed": false
},
{
"app_id": "730",
"context_id": "2",
"number_of_items": 1,
"item_ids": [
"20276522620"
],
"asset_ids": [
"20276522620"
],
"class_id": "469444882",
"instance_id": "302028390",
"market_hash_name": "Tec-9 | Urban DDPAT (Field-Tested)",
"suggested_price": "0.04",
"item_type": "Pistol",
"item_class": null,
"item_rarity": null,
"item_weapon": "Tec-9",
"item_quality": "Consumer Grade",
"item_itemset": "The Bank Collection",
"image": "https://steamcommunity-a.akamaihd.net/economy/image/-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpoor-mcjhoyszMdS1D-OOjhoK0mvLwOq7c2D4B6pwijLiXpt6s3lDkrkJvZG-hLI7Ee1M7YVmC8gO-kunrjZK1tJXXiSw0uDynv1g/256fx256f",
"inspectable": true,
"inspect_link": "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20S76561198248775632A%asset_id%D7936680248821929362",
"phase": null,
"tags": {
"type": "Pistol",
"weapon": "Tec-9",
"collection": "The Bank Collection",
"category": "Normal",
"quality": "Consumer Grade",
"exterior": "Field-Tested"
},
"has_buy_orders": false,
"recent_sales_info": null,
"stickers": null,
"fraud_warnings": [
[]
],
"is_listing_allowed": false
},
{
"app_id": "730",
"context_id": "2",
"number_of_items": 1,
"item_ids": [
"20215185457"
],
"asset_ids": [
"20215185457"
],
"class_id": "4141779477",
"instance_id": "519977179",
"market_hash_name": "Desert Eagle | The Bronze (Factory New)",
"suggested_price": "0.34",
"item_type": "Pistol",
"item_class": null,
"item_rarity": null,
"item_weapon": "Desert Eagle",
"item_quality": "Industrial Grade",
"item_itemset": "The Control Collection",
"image": "https://steamcommunity-a.akamaihd.net/economy/image/-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgposr-kLAtl7PLFTjNX4d6zhpO0leX7PaHUqWdY781lxLCZo9yh3gW3_hJqNj_2Jo6TelI8NQmErlPsyLq90ZPvtJnLm3Ux6CA8pSGK8qELUuc/256fx256f",
"inspectable": true,
"inspect_link": "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20S76561198248775632A%asset_id%D16890227741044942403",
"phase": null,
"tags": {
"type": "Pistol",
"weapon": "Desert Eagle",
"collection": "The Control Collection",
"category": "Normal",
"quality": "Industrial Grade",
"exterior": "Factory New"
},
"has_buy_orders": false,
"recent_sales_info": {
"hours": "18.86",
"average_price": "0.27"
},
"stickers": null,
"fraud_warnings": [
[]
],
"is_listing_allowed": true
},

You are using innerHTML so your content is override and only last one display .Instead you can generate htmls in your each loop and append same to some div .
Demo Code :
var data = {
"status": "success",
"data": {
"steam_inventory": {
"items": [{
"market_hash_name": "Prisma 2 Case",
"image": "https://steamcommunity-a.akamaihd.net/economy/image/-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXU5A1PIYQNqhpOSV-fRPasw8rsUFJ5KBFZv668FFU1nfbOIj8W7oWzkYLdlPOsMOmIk2kGscAj2erE99Sn2AGw_0M4NW2hIYOLMlhpcmY0CRM/256fx256f",
},
{
"market_hash_name": "Tec-9 | Urban DDPAT (Field-Tested)",
"image": "https://steamcommunity-a.akamaihd.net/economy/image/-9a81dlWLwJ2UUGcVs_nsVtzdOEdtWwKGZZLQHTxDZ7I56KU0Zwwo4NUX4oFJZEHLbXH5ApeO4YmlhxYQknCRvCo04DEVlxkKgpoor-mcjhoyszMdS1D-OOjhoK0mvLwOq7c2D4B6pwijLiXpt6s3lDkrkJvZG-hLI7Ee1M7YVmC8gO-kunrjZK1tJXXiSw0uDynv1g/256fx256f",
}
]
}
}
}
$(data.data.steam_inventory.items).each(function(index, value) {
var marketname = value.market_hash_name
var urlicon = value.image
//append datas
$("#result").append("<div><img class='outputIconURL' src='" + urlicon + "' width='350' height='300'><p class='outputName'>" + marketname + "</p></div>")
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="result">
<!--result will cme here--->
</div>

Related

How to update nested object property in array by id in javascript?

How can i updated isCompleted property to true on onClick. I can only access moduleContent id from route e.g.- "id": "cr1mod1content1". How can i update isCompleted property to true by only matching this id. Note: i'm using react/nextJS for this project.
here is my json data structure.
[
{
"id": 1,
"progress": 0,
"title": "Python Basics for Data Science",
"modules": [
{
"id": "cr1mod1",
"title": "Module 1- Python Basics",
"moduleContent": [
{
"type": "html",
"id": "cr1mod1content1",
"title": "Module Introduction and Learning Objectives",
"content": " <p> This module teaches the basics of Python and begins </p>",
"quizContent": [],
"isCompleted": false
},
{
"type": "video",
"id": "cr1mod1content2",
"title": "Video: Types (3:02)",
"content": "https://vimeo.com/23",
"quizContent": [],
"isCompleted": false
},
{
"type": "quiz",
"id": "cr1mod1content3",
"title": "Practice Quiz: Types",
"content": "",
"quizContent": [],
"isCompleted": false
}
]
},
{
"id": "cr1mod2",
"title": "Module 2 - Python Data Structures",
"moduleContent": [
{
"type": "html",
"id": "cr1mod2content1",
"title": "Module Introduction and Learning Objectives",
"content": " <p>This module begins a journey into Python data structure</p> ",
"quizContent": [],
"isCompleted": false
},
{
"type": "video",
"id": "cr1mod2content2",
"title": "Video: Types (8:31)",
"content": "https://vimeo.com/1",
"quizContent": [],
"isCompleted": false
},
{
"type": "quiz",
"id": "cr1mod2content3",
"title": "Practice Quiz: Types",
"content": "",
"quizContent": [],
"isCompleted": false
}
]
}
]
}
]
You can reach this in this way:
const arr = declare Your JSON array there
const id = 'cr1mod2content3'
for(const module of arr[0].modules) {
for(const item of module.moduleContent) {
if(item.id === id) item.isCompleted = true
}
}
Take into account that if your root JSON array may contain several elements, you will have to wrap the cycle with one more (root) iteration.
You can use some() of array for checking and update
const data = [
{
"id": 1,
"progress": 0,
"title": "Python Basics for Data Science",
"modules": [
{
"id": "cr1mod1",
"title": "Module 1- Python Basics",
"moduleContent": [
{
"type": "html",
"id": "cr1mod1content1",
"title": "Module Introduction and Learning Objectives",
"content": " <p> This module teaches the basics of Python and begins </p>",
"quizContent": [],
"isCompleted": false
},
{
"type": "video",
"id": "cr1mod1content2",
"title": "Video: Types (3:02)",
"content": "https://vimeo.com/23",
"quizContent": [],
"isCompleted": false
},
{
"type": "quiz",
"id": "cr1mod1content3",
"title": "Practice Quiz: Types",
"content": "",
"quizContent": [],
"isCompleted": false
}
]
},
{
"id": "cr1mod2",
"title": "Module 2 - Python Data Structures",
"moduleContent": [
{
"type": "html",
"id": "cr1mod2content1",
"title": "Module Introduction and Learning Objectives",
"content": " <p>This module begins a journey into Python data structure</p> ",
"quizContent": [],
"isCompleted": false
},
{
"type": "video",
"id": "cr1mod2content2",
"title": "Video: Types (8:31)",
"content": "https://vimeo.com/1",
"quizContent": [],
"isCompleted": false
},
{
"type": "quiz",
"id": "cr1mod2content3",
"title": "Practice Quiz: Types",
"content": "",
"quizContent": [],
"isCompleted": false
}
]
}
]
}
]
const updateData = (arr, idFilter) => {
arr.some(({modules}) => {
modules.some(({moduleContent}) => {
moduleContent.some(ele => {
if (ele.id === idFilter) {
return ele.isCompleted = true
}
return false
})
})
})
}
updateData(data, 'cr1mod1content1')
console.log(data)
You can use map double times to update
data[0].modules.map(item => item.moduleContent.map(obj => {
if (obj.id === "cr1mod1content1") {
obj.isCompleted = true
}
}));

For Stripe Connected Accounts, which part of the account.updated webhook object indicates that the account is enabled?

I have an endpoint that is receiving events from Connected Stripe accounts. The webhook listens for the account.updated event type. It works as expected. However, when I look at the object sent to my endpoint, I'm not sure what would indicate that the account is in "enabled" status. I ask because if the Connected account was successfully set up, I would like to then give the customer the ability to access their Stripe dashboard. If it's not, then I would want for them to be able to finish the account setup process. Any insight would be appreciated. This is what I get from the Stripe webhook:
{
"id": "EXAMPLEID",
"object": "event",
"account": "ACCOUNT",
"api_version": "2020-03-02",
"created": 1608614938,
"data": {
"object": {
"id": "ACCOUNTNUMBER",
"object": "account",
"business_profile": {
"mcc": null,
"name": null,
"support_address": null,
"support_email": null,
"support_phone": null,
"support_url": null,
"url": null
},
"capabilities": {
"transfers": "active"
},
"charges_enabled": true,
"country": "US",
"default_currency": "usd",
"details_submitted": true,
"email": null,
"payouts_enabled": true,
"settings": {
"bacs_debit_payments": {
},
"branding": {
"icon": null,
"logo": null,
"primary_color": null,
"secondary_color": null
},
"card_payments": {
"statement_descriptor_prefix": null,
"decline_on": {
"avs_failure": false,
"cvc_failure": false
}
},
"dashboard": {
"display_name": "Books For Everyone",
"timezone": "Etc/UTC"
},
"payments": {
"statement_descriptor": null,
"statement_descriptor_kana": null,
"statement_descriptor_kanji": null
},
"sepa_debit_payments": {
},
"payouts": {
"debit_negative_balances": true,
"schedule": {
"delay_days": 2,
"interval": "daily"
},
"statement_descriptor": null
}
},
"type": "express",
"created": 1608614884,
"external_accounts": {
"object": "list",
"data": [
{
"id": "ID_NUMBER_HERE",
"object": "bank_account",
"account": "ACCOUNT_NUMBER_HERE",
"account_holder_name": null,
"account_holder_type": null,
"available_payout_methods": [
"standard"
],
"bank_name": "STRIPE TEST BANK",
"country": "US",
"currency": "usd",
"default_for_currency": true,
"fingerprint": "x9ELfUw7u81waQkl",
"last4": "6789",
"metadata": {
},
"routing_number": "110000000",
"status": "new"
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/accounts/ACCOUNT_NUMBER/external_accounts"
},
"login_links": {
"object": "list",
"total_count": 0,
"has_more": false,
"url": "/v1/accounts/ACCOUNT_NUMBER/login_links",
"data": [
]
},
"metadata": {
},
"requirements": {
"current_deadline": null,
"currently_due": [
],
"disabled_reason": null,
"errors": [
],
"eventually_due": [
"individual.dob.day",
"individual.dob.month",
"individual.dob.year",
"individual.ssn_last_4"
],
"past_due": [
],
"pending_verification": [
]
},
"tos_acceptance": {
"date": 1608614937
}
},
"previous_attributes": {
"capabilities": {
"transfers": "inactive"
},
"charges_enabled": false,
"details_submitted": false,
"payouts_enabled": false,
"requirements": {
"currently_due": [
"tos_acceptance.date",
"tos_acceptance.ip"
],
"disabled_reason": "requirements.past_due",
"eventually_due": [
"individual.dob.day",
"individual.dob.month",
"individual.dob.year",
"individual.ssn_last_4",
"tos_acceptance.date",
"tos_acceptance.ip"
],
"past_due": [
"tos_acceptance.date",
"tos_acceptance.ip"
]
},
"tos_acceptance": {
"date": null
}
}
},
"livemode": false,
"pending_webhooks": 1,
"request": {
"id": "ID_NUMBER_HERE",
"idempotency_key": null
},
"type": "account.updated"
}
Because there are now multiple things an account might be used for, there isn't necessarily one single attribute to check for being "enabled" overall. Mostly you'll want to look at the capabilities (docs, API reference) such as in your data where you see transfers: 'active', which indicates that account is currently enabled for transfers.
You'll also want to keep an eye on the requirements hash (docs, API ref), which is how Stripe will inform you that additional information is needed now (or eventually).

mongoose unable to make nested search through "field.attributes"

newFormName = req.body.name;
newFormQuestions = req.body.questions;
formId = req.body.formId;
User.updateOne(
{
"forms._id": formId,
},
{
$set: {
"forms.$.name": newFormName,
"forms.$.questions": newFormQuestions,
},
},
(errUpdate, resultUpdate) => {
if (errUpdate) {
return res.status(500).json({ sucess: false, error: errUpdate });
} else {
return res.status(200).json({ sucess: true, data: resultUpdate });
}
}
);
the above code is responsible to update certain field in the user database.
Example of how user data looks like
[{
"enrolledEventID": [],
"isOrganiser": true,
"isAdmin": false,
"forms": [
{
"questions": [
{
"questionType": "Text",
"textInputLabelName": "asdsadsad"
},
{
"questionType": "Text",
"textInputLabelName": "asdasdasdasd"
}
],
"_id": "5f6070b5002a5249b050bd1e",
"name": "Test Form 4",
"dateCreated": "2020-09-15T07:43:49.389Z",
"__v": 0
},
{
"questions": [
{
"questionType": "Text",
"textInputLabelName": "asdsadsad"
},
{
"questionType": "Text",
"textInputLabelName": "asdasdasdasd"
}
],
"_id": "5f607140cd6faa39241f7c8a",
"name": "Test Form 56",
"dateCreated": "2020-09-15T07:46:08.012Z",
"__v": 0
},
{
"questions": [
{
"questionType": "Rating",
"textInputQuestionTitle": "asdasdasd",
"totalRating": 0
},
{
"questionType": "Text",
"textInputLabelName": "asdasdasdasd"
},
{
"questionType": "Text",
"textInputLabelName": "asdasdasdasdasd"
}
],
"_id": "5f6315145e6c794e78bcce73",
"name": "New Form",
"dateCreated": "2020-09-17T07:49:40.307Z",
"__v": 0
},
{
"questions": [
{
"questionType": "Rating",
"textInputQuestionTitle": "asdasdasdsadad",
"totalRating": 0
}
],
"_id": "5f6316895e6c794e78bcce74",
"name": "New Formasdasdasd",
"dateCreated": "2020-09-17T07:55:53.537Z",
"__v": 0
},
{
"questions": [
{
"questionType": "Text",
"textInputLabelName": "asdsadsad"
},
{
"questionType": "Text",
"textInputLabelName": "asdasdasdasd"
}
],
"_id": "5f632b0f12f05d5028c96942",
"name": "Test Form 23232323",
"dateCreated": "2020-09-17T09:23:27.137Z",
"__v": 0
}
],
"_id": //id,
"fullname": //name,
"email": //hotmail,
"password": //password,
"__v": 0
},
{
"enrolledEventID": [],
"isOrganiser": true,
"isAdmin": false,
"forms": [],
"_id": //id,
"fullname": //name,
"email": //email,
"password": //password,
"__v": 0
} ]
and the problem is that the match will always return 0, I'm new to mongoose and it seems that I should be able to access to the forms._id through "forms._id" in the criteria after done some research, what did I do wrong ?
I have ensured that the formId is existed in the user data.
Make sure newFormQuestions have the same object keys with questions.
Do console.log for every step you aren't sure of.
As an alternative for this mongoose update, use
const temp = User.find({forms._id:formId}) first,
then you could use User.save() after assigning the value into the object you've found.
Good Luck ^^

I want to sort some parameters but gives me [object object] or not undefined

"text": "Introducing the Twitter Certified Products Program:
"retweet_count": 121,
"in_reply_to_status_id_str": null,
"id": 240859602684612608,
"geo": null,
"retweeted": false,
"possibly_sensitive": false,
"in_reply_to_user_id": null,
"place": null,
"user": {
"profile_sidebar_fill_color": "DDEEF6",
"profile_sidebar_border_color": "C0DEED",
"profile_background_tile": false,
"name": "Twitter API",
"profile_image_url": "http://a0.twimg.com/profile_images/2284...
"created_at": "Wed May 23 06:01:13 +0000 2007",
"location": "San Francisco, CA",
"follow_request_sent": false,
"profile_link_color": "0084B4",
"is_translator": false,
"id_str": "6253282",
"entities": {
"url": {
"urls": [
{
"expanded_url": null,
"url": "",
"indices": [
0,
22
]
}
]
},
"description": {
"urls": [
]
}
},
jquery
success: function(data) {
var result = JSON.parse(data); $.each(result, function (i, val) {
document.write(val.text+" "+val.retweet_count+"
");
});
"text": "Introducing the Twitter Certified Products Program:
It should be:
"text": "Introducing the Twitter Certified Products Program:",
You are missing a " and a comma.

How to Accessing fields from custom search results in netsuite?

In the ui, I have created a custom transaction search with vendor lines. How do I access vendor lines values? I have something like this:
var veResults = vendorSearch.run().getRange({
start: 0,
end: 50
});
for(var i = 0; i < veResults.length; i++)
{
var vendorName = veResults[i].getValue({name: 'vendorLine.entityid');
context.response.write(vendorName);
};
If I print veResults, I get the following json:
[
{
"recordType": "vendorpayment",
"id": "210",
"values": {
"employee.entityid": "",
"trandate": "5/20/2015",
"print": "Print",
"type": [
{
"value": "VendPymt",
"text": "Bill Payment"
}
],
"payrollbatch": "",
"tranid": "2009",
"entity": [
{
"value": "35",
"text": "Pacific Bell Telephone"
}
],
"account": [
{
"value": "1",
"text": "1000 Checking"
}
],
"otherrefnum": "",
"statusref": [],
"trackingnumbers": "",
"memo": "",
"currency": [
{
"value": "1",
"text": "USA"
}
],
"expectedreceiptdate": "",
"trandate_1": "5/20/2015",
"enddate": "",
"item": [],
"vendorLine.entityid": "Pacific Bell Telephone",
"vendorLine.billaddress": "Pacific Bell Telephone\nPacific Bell Payment Center\nSacramento CA 95887-0001\nUS"
}
...]
So, the value is there, how do I get it? The search object has only getValue and getText methods, none of which work in this case.
There is a syntax error with this line
var vendorName = veResults[i].getValue({'vendorLine.entityid');
It should be
var vendorName = veResults[i].getValue('vendorLine.entityid');

Categories