javascript-objects

How to remove all getters and setters from an object in Javascript and keep pure value

依然范特西╮ 提交于 2019-12-11 05:05:20
问题 I'm using a library called which takes a JS object as an input. Unfortunately, the JSONP api that I am using returns an object containing getters and setters, which this particular library does not know how to handle. How can I remove all getters and setters from an object while retaining the values of the properties, so I have a Plain Old JavaScript Object? 回答1: a solution for this special case/environment/setting might look like that ... var obj = JSON.parse(JSON.stringify(model)); console

Access to object property with dynamic name and dynamic nesting level

扶醉桌前 提交于 2019-12-11 04:59:13
问题 I read the property of an object I want to access from a string: level1.level2.property OR level1.property OR ... The names and the nesting may vary. I store the objects in a separate module (workerFunctions). I know that I can access the objects dynamically with the []notation, e.g.: var level1="level1"; var property="property"; console.log(workerFunctions[level1][property]) However, I don't know how to construct this "workerFunctions[level1][property]" dynamically from varying input strings

Typescript: what could be causing this error? “Element implicitly has an 'any' type because type 'Object' has no index signature”

妖精的绣舞 提交于 2019-12-11 04:48:51
问题 i'm trying to get an array of all the keys in an object with nested properties, my code: public static getKeys(obj: Object) { let keys: string[] = []; for (let k in obj) { if (typeof obj[k] == "Object" && obj[k] !== null) { keys.push(obj[k]); CHelpers.getKeys(<Object>obj[k]); } else { return keys; } } } However, obj[k] is giving me the error "Element implicitly has an 'any' type because type 'Object' has no index signature". i've looked at some other threads with the same error but it seems

Performance concerns when storing data in large arrays with Javascript

空扰寡人 提交于 2019-12-11 01:59:39
问题 I have a browser-based visualization app where there is a graph of data points, stored as an array of objects: data = [ {x: 0.4612451, y: 1.0511} , ... etc ] This graph is being visualized with d3 and drawn on a canvas (see that question for an interesting discussion). It is interactive and the scales can change a lot, meaning the data has to be redrawn, and the array needs to be iterated through quite frequently, especially when animating zooms. From the back of my head and reading other

Data binding to a dynamic path in Polymer

自作多情 提交于 2019-12-11 01:57:19
问题 I am building a web app with Polymer 1.0 and Firebase, and I want to have the view change when data was entered into a path with a user ID in the path. To do that, I want to do something like this: [[question.answers.(user.uid).choice]] Let me explain in more detail. So, in the template, I have something like this: <ul id="question-list"> <template is="dom-repeat" items="[[questions]]" sort="_computeSort" as="question"> <li class="card question" data-key="[[question.$key]]" question="[

React setState of for deeply nested value

倾然丶 夕夏残阳落幕 提交于 2019-12-11 01:29:10
问题 I’ve got a very deeply nested object in my React state. The aim is to change a value from a child node. The path to what node should be updated is already solved, and I use helper variables to access this path within my setState. Anyway, I really struggle to do setState within this nested beast. I abstracted this problem in a codepen: https://codesandbox.io/s/dazzling-villani-ddci9 In this example I want to change the child’s changed property of the child having the id def1234 . As mentioned

React set state property dynamically

淺唱寂寞╮ 提交于 2019-12-11 01:13:29
问题 I'm using react and I have some methods to set the state of my COmponent separately. I have the following methods: setLineColor(value){ this.setState({stroke:value},()=>{ this.props.data(this.getStyleData()); }); } setFillColor(value){ this.setState({ fill:value},()=>{ this.props.data(this.getStyleData()); }); } setMode(value){ this.setState({ mode:value},()=>{ this.props.data(this.getStyleData()); }); } How can I combine the methods, so that I can have something like: setAttribute(propery

Merging two backbone collection and models into one object using underscore

廉价感情. 提交于 2019-12-11 00:57:35
问题 I have two backbone collections Categories and Items, Categories contains category models with id, name, and items (w/c contains item ids in string format separated by commas) and Items collection that contains item models(id, name, etc.). How do I merge them into one object that can be easily be rendered in a handlebars template Sample Structure: var Categories = [{'id':'1', 'category_name':'Burgers', 'category_items':'1,2'},{'id':'2','category_name':'Drinks','category_items':'3'}]; var

How do I iterate over this json structure to produce another structure?

蓝咒 提交于 2019-12-11 00:22:35
问题 I have this json structure. x=[{ "value": 1.37, "date_transacted": "2015-01-01" }] From this json structure, I want to produce the following json structure; y1=[{ c: [{ v: "2015-01-01" }, { v: "1.37" }] }] I have written the code to do this. It looks like this; var y1 = [{ c:[ {"v":x[0].value}, {"v":x[0].date_transacted} ] }]; My problem comes when x has several json key/value pairs. Something that look like this; x=[{ "value": 1.37, "date_transacted": "2015-01-01" }, { "value": 1.62, "date

Passing event objects from one function to another

邮差的信 提交于 2019-12-10 22:39:41
问题 I decided to break this onEdit(e) function up into multiple functions, but when I did, the event objects (e) portion got "lost." After messing with it for a while, I finally got it to work again, but I don't think it's the most efficient solution. Any suggestions, or is this good enough? Basically, I just added var e = e; and that made it work again. function onEdit(e){ Logger.log(e); if(e.range.getSheet().getName() == 'Estimate'){ var e = e; Logger.log("Starting subCatDV..."); subCatDV(e);