草庐IT

Property

全部标签

javascript - 如何迭代对象中的内部对象/属性

我有一个对象,它的内部对象和属性定义如下:varobj={obj1:{"prop1":"nothing","prop2":"prop"},obj2:{"prop1":"nothing","prop2":"prop"},pr1:"message",pr2:"mess"};通常要迭代对象的每个属性,for..in循环可以做到这一点for(propertyinobj){if(obj.hasOwnProperty(property)){console.log(property+""+obj[property]);}}控制台显示:obj1[objectObject]obj12[objectObj

javascript - 未捕获的类型错误 : Cannot read property 'length' of undefined

当我尝试从AJAX调用中获取数据并在单击提交按钮时将其插入另一个函数时,如何避免出现以下错误?ajax函数中的console.log调用显示数据已被抓取,我希望然后存储在json_data中。当时的目的是使用此数据来更改通过HTML表单提交的字符串。然后在“点击”函数的行返回错误:console.log(json_data.length);TestForm#results_box{border:red5pxsolid;}#place{border:#cccccc1pxsolid;}$(document).ready(function(){varjson_source="https://

javascript - 在类方法之外声明类属性

查看x和y是如何在构造函数中声明的:classPoint{constructor(x,y){this.x=x;this.y=y;}toString(){return'('+this.x+','+this.y+')';}}有没有办法在函数之外声明属性,例如:classPoint{//Declarestaticclasspropertyhere//a:22constructor(x,y){this.x=x;this.y=y;}toString(){return'('+this.x+','+this.y+')';}}所以我想将a分配给22,但我不确定我是否可以在构造函数之外但仍然在类中这样做

javascript - 通过变量中的键名获取javascript对象属性

这个问题在这里已经有了答案:AssigningpropertytoJSobjectusinganotherobjectspropertyvalueasthepropertyname(1个回答)关闭6年前。假设我在javascripts中有这样的东西:varobj={subObj:{}};vartype='subObj';我怎样才能得到obj'ssubObjw/type?例如我想做这样的事情:obj.(type);

javascript - IE 11 浏览器错误 - 异常 : Object doesn't support property or method 'matches' , 其他浏览器工作正常

就我而言,该网页在firefox和chrome浏览器中运行良好,但在IEv.11中它显示错误为errorcomesinIE11DEVELOPERTOOLS.该错误显示在IE11的开发人员工具中。该错误不允许打开特定链接,单击它会显示以下错误。polyfills.ts-*BROWSERPOLYFILLS*//**IE9,IE10andIE11requiresallofthefollowingpolyfills.**/import'core-js/es6/symbol';import'core-js/es6/object';import'core-js/es6/function';impo

javascript - 错误 :InvalidValueError: setCenter: not a LatLng or LatLngLiteral: in property lat: not a number

functioninitAutocomplete(){varlat=document.getElementById('lat').value;varlng=document.getElementById('lng').value;console.log(lat);console.log(lng);varmap=newgoogle.maps.Map(document.getElementById('map'),{center:{lat:lat,lng:lng},zoom:13,mapTypeId:'roadmap'});}它给了我以下错误:error:InvalidValueError:

javascript - 带有 getter/setter 的 JSON stringify ES6 类属性

我有一个JavaScriptES6类,该类具有使用set设置的属性并使用get函数访问。它也是一个构造函数参数,因此可以使用所述属性实例化该类。classMyClass{constructor(property){this.property=property}setproperty(prop){//Somevalidationetc.this._property=prop}getproperty(){returnthis._property}}我使用_property来避免使用get/set的JS陷阱,如果我直接设置为property会导致无限循环。现在我需要将MyClass的一个实例

javascript - 自定义过滤器在 AngularJS 中给出 "Cannot read property ' 切片' of undefined"

我的自定义startFrom过滤器给我一个错误。app.filter('startFrom',function(){returnfunction(input,start){start=+start;//parsetointreturninput.slice(start);}});app.controller("PostCtrl",function($scope,$http){$scope.currentPage=0;$scope.pageSize=10;$scope.hidePagination=true;$scope.search=function(){$http.get('some

javascript - 未捕获的类型错误 : Cannot read property 'getElementsByTagName' of null

我正在尝试使用.getElementsByTagName()选择元素。vartags=document.body.getElementsByTagName("*");当前尝试使用从现有答案中吸取的教训https://stackoverflow.com/questions/7410949/javascript-document-getelementsbyclassname-compatibility-with-ie/7410966#7410966但是我的尝试失败了,出现了这个错误:UncaughtTypeError:Cannotreadproperty'getElementsByTagN

javascript - 为什么 const 在 JavaScript 中的某些 for 循环中有效?

我知道为什么const在for循环中不起作用。我们需要创建一个新范围并将值复制到其中。所以这不会飞。for(consti=0;i而这会。for(leti=0;i但是,我注意到在像这样循环遍历对象的属性时,它们都可以工作。for(letpropertyinthingy)console.log(property);for(constpropertyinthingy)console.log(property);我不知道为什么。 最佳答案 for(constpropertyinobject)之所以有效,是因为每次迭代都会获得一个新变量,该变