gpt4 book ai didi

javascript - @符号打破 Angular 表达式

转载 作者:行者123 更新时间:2023-11-29 18:04:54 24 4
gpt4 key购买 nike

以下 html 因 @ 符号而中断。除了不使用 @ 符号之外,还有什么解决方法。我必须使用 @ 符号,因为将使用 newtonsoft jsonconvert http://www.newtonsoft.com/json 在 c# web api 中生成 json。从 XML。 jsonconvert 在生成的 json 中使用 @ 符号为 xml 属性添加前缀。

如何解决 @ 符号问题?对我有用的一件事是 message.root.node1["@attr1"]。如果可能,请提供详细说明 Angular 变量/表达式中禁止使用的符号的资源。

<html ng-app="countryApp">
<head>
<meta charset="utf-8">
<title>Angular.js JSON Fetching Example</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script>
var countryApp = angular.module('countryApp', []);
countryApp.controller('CountryCtrl', function ($scope, $http) {
$scope.message = { "root": { "node1": { "@attr1": "1", "@attr2": "2" }, "node2": { "@attr1": "3", "@attr2": "4" } } }

});
</script>
</head>
<body ng-controller="CountryCtrl">
<h2>Angular.js JSON Fetching Example</h2>

<span>
menudatetime {{message.root.node1.@attr1}}
</span>


</body>
</html>

最佳答案

使用message.root.node1['@attr1']

它基本上是 Angular 的 JavaScript 表达式。 message.root.node1.@attr1 不是有效的 javascript...

关于javascript - @符号打破 Angular 表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32061408/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com