Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 在Angular指令中使用JSON方括号表示法访问值_Angularjs - Fatal编程技术网

Angularjs 在Angular指令中使用JSON方括号表示法访问值

Angularjs 在Angular指令中使用JSON方括号表示法访问值,angularjs,Angularjs,我有一个JSON对象,它的一些键中包含名称空间,格式为namespace:key。因此,我需要使用方括号符号而不是点符号来访问其值 我试图使用一些角度指令/过滤器来处理数据,在本例中,我将使用过滤器,但问题似乎也与指令中使用括号表示法有关 下面是我的例子: ng使用HTML中的筛选器重复: <ul> <li ng-repeat="item in items | filter:{properties['namespace:status']}"> {{item.n

我有一个JSON对象,它的一些键中包含名称空间,格式为
namespace:key
。因此,我需要使用方括号符号而不是点符号来访问其值

我试图使用一些角度指令/过滤器来处理数据,在本例中,我将使用
过滤器
,但问题似乎也与指令中使用括号表示法有关

下面是我的例子:

ng使用HTML中的筛选器重复:

<ul>
  <li ng-repeat="item in items | filter:{properties['namespace:status']}">
    {{item.name}}
  </li>
</ul>
{
  "properties":{
    "namespace:status":"A",
    "name":"Potato",
    // ...
  },
  // ...
},
{
  "properties":{
    "namespace:status":"B",
    "name":"Carrot",
    // ...
  },
  // ...
},
{
  "properties":{
    // Note that it doesn't contain the namespace attribute
    "name":"Bean",
    // ...
  },
  // ...
}
<ul>
  <li>Potato</li>
  <li>Carrot</li>
</ul>
预期呈现的HTML:

<ul>
  <li ng-repeat="item in items | filter:{properties['namespace:status']}">
    {{item.name}}
  </li>
</ul>
{
  "properties":{
    "namespace:status":"A",
    "name":"Potato",
    // ...
  },
  // ...
},
{
  "properties":{
    "namespace:status":"B",
    "name":"Carrot",
    // ...
  },
  // ...
},
{
  "properties":{
    // Note that it doesn't contain the namespace attribute
    "name":"Bean",
    // ...
  },
  // ...
}
<ul>
  <li>Potato</li>
  <li>Carrot</li>
</ul>
告诉我一个语法错误

我的问题是相同的表达式
{properties['namespace:status']}
确实符合模板中的语法,因此我不确定我是否做错了什么,或者指令是否无法处理括号表示法


如果是后者,有没有关于如何在不重写JSON的情况下实现这一点的建议?

您应该指定这样的对象键

<ul>
  <li ng-repeat="item in items | filter:{prop: properties['namespace:status']}">
    {{item.name}}
  </li>
</ul>
在这里你可以查一下


但您应该知道angularjs不能按对象属性数组过滤,它只能是数组。

就是这样。关于对象属性数组的事情,我可能最终会使用不同的指令