我需要检查一个给定的属性是否存在于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"
}
&#34;标题&#34;后面最多可以有5个属性。属性和我只需要显示收到的属性,这意味着如果JSON响应中不存在属性,则应删除或隐藏li元素。
我的上述方法仍然没有隐藏li元素,我无法对不存在的属性进行任何检查。
不要介意标题前的属性。
答案 0 :(得分:0)
应该是
<li ng-show="@Model.punkt1">@Model.punkt1</li>