如何检查属性是否存在于Angular App的JObject中 [英] How to check whether a property exists in a JObject in an Angular App

查看:268
本文介绍了如何检查属性是否存在于Angular App的JObject中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查JObject中是否存在给定属性,以便与我的Angular应用程序的ng-show指令一起使用.

I need to check whether a given property exists in a JObject, to use with my ng-show directive for my Angular app.

我尝试使用方括号语法访问属性:

I tried accessing the property using the square brackets syntax:

<li ng-show="@Model["punkt1"] != null">@Model.punkt1</li>

这是JSON响应的示例:

This is an example of a JSON response:

{
  "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"
}

"heading"属性后最多可以有5个属性,我只需要显示接收到的属性,这意味着如果JSON响应中不存在li元素,则应该将其删除或隐藏.

There can be up to 5 properties after the "heading" property and I only need to display the ones that are received, meaning the li elements should be removed or hidden if the property is not present in the JSON response.

我上面的方法仍然没有隐藏li元素,并且我无法对不存在的属性进行任何检查.

My above method still doesn't hide the li elements and I am not able to do any checks on properties that do not exist.

在标题之前不要介意属性.

Don't mind the properties before the heading.

推荐答案

应为

<li ng-show="@Model.punkt1">@Model.punkt1</li>

这篇关于如何检查属性是否存在于Angular App的JObject中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆