在angularjs中,如何遍历数组并从受尊重的标签中获取值并相互计数并返回值?
例如,我有一个这样的数组:
"contractorsList": [
{
"name": "KP/A995/29",
"percent": 78
},
{
"name": "KP/A574/69",
"percent": 33
},
{
"name": "KP/A520/30",
"percent": 38
},
{
"name": "KP/A787/57",
"percent": 35
},
{
"name": "KP/A850/75",
"percent": 49
},
{
"name": "KP/A374/17",
"percent": 47
},
{
"name": "KP/A962/40",
"percent": 33
}
]
Run Code Online (Sandbox Code Playgroud)
这里有一个字段percent,我想迭代对象,需要得到百分比的总值.(添加每个百分比来收集)
什么是正确的方法来做到这一点 angular.js
我试过这样,但我没有得到任何价值:
scope.totalContracts = $filter('filter')( contractorsList, {percent:!null});
//i assumed to get the total values as array, so that i can add.
Run Code Online (Sandbox Code Playgroud) 我做了一个简单的折线图。我已将网格添加到axis但我想保留它们dotted,dashed所以我该怎么做?
var margin = {top: 20, right: 100, bottom: 30, left: 100},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var dataset = [
{x: 0, y: 5},
{x: 1, y: 8},
{x: 2, y: 13},
{x: 3, y: 12},
{x: 4, y: 16},
{x: 5, y: 21},
{x: 6, y: 18},
{x: 7, y: 23},
{x: 8, y: 24},
{x: 9, y: 28},
{x: 10, y: 35}, …Run Code Online (Sandbox Code Playgroud)我是新手,rxjs我正在尝试控制click事件,因为我正在使用此功能:
$(function(){
Rx.Observable.fromEvent(document, 'click')
.filter(function(c) {
console.log('c', c); //but nothing consoles..?
})
});
Run Code Online (Sandbox Code Playgroud)
但对我来说没什么安慰......问题是什么?谁能解释我在这里做的错误?
我正在尝试从 setTimeout 获取值。但控制台没有给出任何结果。如何处理这个async功能?任何人都可以帮助我以正确的方式理解这一点吗?
这是我的尝试:
async function getTheme() {
const value = 'abc'
setTimeout(() => {
return value;
}, 3000);
}
getTheme().then(time => console.log(time)); //getting no result.
Run Code Online (Sandbox Code Playgroud) 我正在使用$.each- 方法实现追加操作.结果很有趣(元素的时间加倍!).我可能有一些解决方法来解决这个问题.
但是我想在这里理解真正的问题,还有一种方法可以用jQuery自己的方式解决这个问题吗?
提前致谢.
var data = ["orange", "apple"];
var temp = function() {
var template = '<dl class="dropdown"><dt> <div class ="dropdownclass" ><span class="hida">Select</span> <span class="multiSel"></span> </div></dt><dd><div class="mutliSelect"><ul><li><input type="checkbox" value="Control" />Control Node</li><li><input type="checkbox" value="Border" />Border Node</li</ul></div></dd></dl>';
return $(template).clone();
}
$(document).ready(function() {
var tr;
var ut
$.each(data, function(i, value) {
tr = $('<tr />', {
id: i + 'id'
});
ut = temp();
ut.addClass('hema' + i).click(function() {
alert($(this).prop('class'));
});
tr.append(ut);
tr.appendTo('tbody'); //getting multple instance!!!
})
})Run Code Online (Sandbox Code Playgroud)
<script …Run Code Online (Sandbox Code Playgroud)我试图IP address使用以下javascript随机方法创建假.但不行.
任何人帮我找到正确的方法吗?
这是我的尝试:我看起来像("192.168.10.2")
console.log( Math.random(256) + "." + Math.random(256) + "." + Math.random(256) + "." + Math.random(256) );
Run Code Online (Sandbox Code Playgroud) 我要求有条件地返回 true 或 false。如果我的数组包含 aempty, null, undefined,""我需要返回 false。否则是真的。
有没有简单正确的返回方式?
这是我正在寻找的:
var ar = ["apple", '', undefined, null ]; //false
var ar = ["apple", 'Orange', undefined, null ]; //false
var ar = ["apple", 'Orange', "gova", null ]; //false
var ar = ["apple", 'Orange', "gova", "mango" ]; //true
Run Code Online (Sandbox Code Playgroud)
如何辨别假与真?
我正在使用新的angularjs v1.5.7但我不知道我的代码有什么问题,我的应用程序根本没有运行.
这是我的html文件:
<!DOCTYPE html ng-app="myApp">
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Testing App</title>
<link rel="stylesheet" href="">
<script src="angular.js"></script>
</head>
<body ng-controller="main">
<h1>Testing page {{2+2}} {{name}}</h1> //i am not getting any result
<script src="app.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是我的app.js文件:
angular.module('myApp', []);
angular.module('myApp').controller('main', function ($scope) {
alert('hi')
$scope.name = "testing";
});
Run Code Online (Sandbox Code Playgroud)
我在这里没有得到任何错误或工作输出.有人帮我吗?并纠正我?