[英]Why I am getting $parse error when use it on object with array?
I have two json files. 我有两个json文件。 I am getting them like this:
我正在这样得到他们:
var fr, en;
$.getJSON('fr.json', function(data) {
fr = data;
}).complete(function() {
...
});
$.getJSON('en.json', function(data) {
en = data;
}).complete(function() {
...
});
This files are locale files. 该文件是语言环境文件。 I want to test them.
我想测试一下。 I want to compare objects fr and en by property names, so unit test will show, when something is missing in locale file.
我想通过属性名称比较对象fr和en,以便在语言环境文件中缺少某些内容时显示单元测试。
To get what properties are missing in EN locale I am using this algorithm: 为了获得EN语言环境中缺少的属性,我正在使用以下算法:
$parse(*path*)(fr);
$parse(*path*)(fr);
and if it returns something -> EN locale has same property as FR locale has. So my problem. 所以我的问题。 I have such string in file fr.
我在文件fr中有这样的字符串。 "some": { "numbers": ["one", "two", "three"] ... } In first step, I got such property paths:
“ some”:{“数字”:[“一个”,“两个”,“三个”] ...}在第一步中,我得到了这样的属性路径:
some.numbers.0
some.numbers.1
some.numbers.2
And when I am trying to $parse this paths on EN locale I got this error: 当我尝试在EN语言环境中解析此路径时,出现此错误:
Error: [$parse:syntax] Syntax Error: Token '.0' is an unexpected token at column 15 of the expression [addForm.messages.numbers.0] starting at [.0].
http://errors.angularjs.org/1.4.3/$parse/syntax?p0=.0&p1=is%20an%20unexpected%20token&p2=25&p3=some.numbers.0&p4=.0
How can I get working $parse on objects, which contain arrays? 如何在包含数组的对象上使用$ parse? Or is there any other way to do what I need?
还是有其他方法可以满足我的需求?
As @charlietfl mentioned in his comment to the question: 正如@charlietfl在对问题的评论中提到的那样:
Object doesn't have those properties, numbers is an array.
对象没有那些属性,数字是一个数组。 Need to use proper javascript object/array notation
需要使用正确的javascript对象/数组表示法
So, I need use 所以,我需要使用
some.numbers[0]
some.numbers[1]
etc
instead of 代替
some.numbers.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.