我知道我们可以轻松地对json对象或数组使用ng-repeat,如:
<div ng-repeat="user in users"></div>
Run Code Online (Sandbox Code Playgroud)
但是我们如何才能将ng-repeat用于词典,例如:
var users = null;
users["182982"] = "{...json-object...}";
users["198784"] = "{...json-object...}";
users["119827"] = "{...json-object...}";
Run Code Online (Sandbox Code Playgroud)
我想用用户词典:
<div ng-repeat="user in users"></div>
Run Code Online (Sandbox Code Playgroud)
可能吗?.如果是,我怎么能在AngularJs中做到这一点?
我的问题示例:在C#中我们定义了如下字典:
Dictionary<key,value> dict = new Dictionary<key,value>();
//and then we can search for values, without knowing the keys
foreach(var val in dict.Values)
{
}
Run Code Online (Sandbox Code Playgroud)
是否有内置函数从c#中返回字典中的值?
我想做的事情如下:
<div ng-controller="TestCtrl">
<div ng-repeat="(k,v) in items | filter:hasSecurityId">
{{k}} {{v.pos}}
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
AngularJs部分:
function TestCtrl($scope)
{
$scope.items = {
'A2F0C7':{'secId':'12345', 'pos':'a20'},
'C8B3D1':{'pos':'b10'}
};
$scope.hasSecurityId = function(k,v)
{
return v.hasOwnProperty('secId');
}
}
Run Code Online (Sandbox Code Playgroud)
但不知何故,它向我展示了所有项目.如何过滤(键,值)?
如何使用NG-重复类似的 Javascript中?
例:
<div ng-repeat="4">Text</div>
Run Code Online (Sandbox Code Playgroud)
我想用ng-repeat迭代4次,但我该怎么做呢?
当我用ng-repeat迭代一些数组时,我想在filter中使用参数
例:
HTML的部分:
<tr ng-repeat="user in users | filter:isActive">
Run Code Online (Sandbox Code Playgroud)
JavaScript的部分:
$scope.isActive = function(user) {
return user.active === "1";
};
Run Code Online (Sandbox Code Playgroud)
但我希望能够使用像过滤器一样
<tr ng-repeat="user in users | filter:isStatus('4')">
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我怎么能这样做?
我有服务
app.service('myService', function() {
this.list = [];
this.execute = function() {
//this.list is reachable here
angular.forEach(AnArrayHere, function(val, key) {
//this.list is not reachable here
});
}
}
Run Code Online (Sandbox Code Playgroud)
甚至在控制器中也可访问
function Ctrl($scope, myService) {
$scope.list = myService.list;
}
Run Code Online (Sandbox Code Playgroud)
有人可以解释为什么在angular.foreach中无法访问"this.list",我该如何访问"this.list"?
我有一个包含JSON对象的数组(_users).
{
"User":
{
"userid":"19571",
"status":"7",
"active":"1",
"lastlogin":"1339759025307",
"Stats":
[
{
"active":"1",
"catid":"10918",
"typeid":"71",
"Credits":
[
{
"content":"917,65",
"active":"1",
"type":"C7"
},
{
"content":"125,65",
"active":"1",
"type":"B2"
}
]
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
1-如何仅过滤"有效"的用户:"1"不是"0"
我尝试过这样的事情:
<div ng-repeat="user in _users | filter:active | orderBy:user.userid">
{{user.userid}}
</div>
Run Code Online (Sandbox Code Playgroud)
但对我来说工作不正常.
谢谢!
我想在ng-repeat中使用正则表达式.我尝试了以下代码,但它无法正常工作.
<div ng-repeat="user in users | filter:{'type':/^c5$/}"></div>
Run Code Online (Sandbox Code Playgroud)
我有用户数组,我只想显示类型为c5的用户.
如果我使用
filter:{'type':'c5'}
Run Code Online (Sandbox Code Playgroud)
然后它也显示类型为"ac5x"的用户,因为它包含c5.
我怎么解决这个问题?也许有另一种解决方案.
谢谢!
我正在使用JQuery.cookies来管理cookie.我正在存储对象和用户/登录信息.
有没有办法加密或保护cookie?或者只能使用SSL?
在动态更改时,是否可以知道元素旧值和新值?
例如,我有一个值为190的按钮
<button name="btn1" directiveX>190</button>
Run Code Online (Sandbox Code Playgroud)
此按钮将由socket.io动态更改.当它改变时,我需要比较这些值,如果新值高于旧值.
谢谢!
I have over 500 buttons on the page.
<button class="btn-x">test</button>
Run Code Online (Sandbox Code Playgroud)
jQuery:
// #1
$('button[class*="btn-x"]').live('click', function() { }});
// #2
$('.btn-x').live('click', function() { }});
Run Code Online (Sandbox Code Playgroud)
Which call is efficient now, calling directly by class or button[attr*], I want to know it, because it can cause problem later when I have more then 500 buttons but I am not sure if they affect the same result.
javascript ×9
angularjs ×8
frameworks ×3
jquery ×2
json ×2
dictionary ×1
foreach ×1
html ×1
ng-repeat ×1
regex ×1