【发布时间】:2017-09-01 12:08:10
【问题描述】:
我需要检查给定属性是否存在于 JObject 中,以便与我的 Angular 应用程序的 ng-show 指令一起使用。
我尝试使用方括号语法访问该属性:
<li ng-show="@Model["punkt1"] != null">@Model.punkt1</li>
这是 JSON 响应的示例:
{
"value": null,
"editor": {
"name": "Infobox",
"alias": "infobox",
"view": "/App_Plugins/MyGridEditor/infobox.html",
"render": "/App_Plugins/MyGridEditor/infobox.cshtml",
"icon": "icon-grid",
"config": {}
},
"active": false,
"heading": "Toiletter",
"punkt1": "qwert",
"punkt2": "qwert"
}
“标题”属性之后最多可以有 5 个属性,我只需要显示接收到的属性,这意味着如果 JSON 响应中不存在该属性,则应删除或隐藏 li 元素。
我上面的方法仍然没有隐藏 li 元素,我无法对不存在的属性进行任何检查。
不要介意标题前的属性。
【问题讨论】:
标签: c# angularjs json properties conditional-statements