ng-repeat中的angular Infinite $ digest循环(angular Infinite $digest Loop in ng-repeat)
我想在ng-repeat属性中调用函数,这是我的代码
HTML
<body ng-controller="mainCtrl"> <div ng-repeat='item in getGroupedRange() track by item.id'> <span>{{item.val}}</span> <span>{{item.abs}}</span> <span>{{item.rel}}</span> <span>{{item.cum}}</span> </div> </body>
JS
$scope.getGroupedRange = function() { return [ { val: 1, abs: 1, rel: 1, cum: 1, id: 123456 } ]; };
当我打开控制台时,我注意到了错误
10 $digest() iterations reached. Aborting! Watchers fired in the last 5 iterations: [[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":9,"oldVal":8}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":10,"oldVal":9}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":11,"oldVal":10}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":12,"oldVal":11}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":13,"oldVal":12}]]
我的代码的主要目标是使用ng-repeat中的函数来计算每个事件循环中的数据
I want to call function in ng-repeat attribute, here is my code
html
<body ng-controller="mainCtrl"> <div ng-repeat='item in getGroupedRange() track by item.id'> <span>{{item.val}}</span> <span>{{item.abs}}</span> <span>{{item.rel}}</span> <span>{{item.cum}}</span> </div> </body>
js
$scope.getGroupedRange = function() { return [ { val: 1, abs: 1, rel: 1, cum: 1, id: 123456 } ]; };
When I opened console I noticed the error
10 $digest() iterations reached. Aborting! Watchers fired in the last 5 iterations: [[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":9,"oldVal":8}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":10,"oldVal":9}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":11,"oldVal":10}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":12,"oldVal":11}],[{"msg":"fn: function (c,d,e,f){e=a(c,d,e,f);return b(e,c,d)}","newVal":13,"oldVal":12}]]
The main goal of my code is using function in ng-repeat for calculating data in each event loop
原文:https://stackoverflow.com/questions/33847336
最满意答案
首先,添加一些错误检查。 测试输入后
wcin.good()
返回的内容以及wcout.good()
在“你输入”打印后返回的内容是什么? 我怀疑其中一个会返回false
。您的
LANG
和LC_*
环境变量设置为什么?
然后尝试通过在main()
的顶部添加它来解决这个问题:wcin.imbue(std::locale("")); wcout.imbue(std::locale(""));
wcin.imbue(std::locale("")); wcout.imbue(std::locale(""));
我现在手边没有我的Ubuntu,所以我在这里失明并大多猜测。
UPDATE
如果上面的建议没有帮助,那么尝试构建这样的语言环境,并改为使用
imbue()
这个语言环境。std::locale loc ( std::locale (), new std::codecvt_byname<wchar_t, char, std::mbstate_t>("")));
更新2
这对我有用。
关键是也要设置C语言环境。恕我直言,这是GNU C ++标准库实现中的一个错误。除非我弄错了,设置std::locale::global("");
还应该设置C库语言环境。#include <iostream> #include <locale> #include <clocale> #define DUMP(x) do { std::wcerr << #x ": " << x << "\n"; } while (0) int main(){ using namespace std; std::locale loc (""); std::locale::global (loc); DUMP(std::setlocale(LC_ALL, NULL)); DUMP(std::setlocale(LC_ALL, "")); wcin.imbue (loc); DUMP (wcin.good()); wchar_t aChar = 0; wcin >> aChar; DUMP (wcin.good()); DUMP ((int)aChar); wcout << L"You entered " << aChar << L" .\n"; return 0; }
更新3
我很困惑,现在我再也无法重现它并设置
std::locale::global(loc);
似乎做了正确的事情wrt / C语言环境。First, add some error checking. Test what does
wcin.good()
return after the input and what doeswcout.good()
return after the "You entered" print? I suspect one of those will returnfalse
.What are your
LANG
andLC_*
environment variables set to?
Then try to fix this by adding this at the top of yourmain()
:wcin.imbue(std::locale("")); wcout.imbue(std::locale(""));
I do not have my Ubuntu at hand right now, so I am flying blind here and mostly guessing.
UPDATE
If the above suggestion does not help then try to construct locale like this and
imbue()
this locale instead.std::locale loc ( std::locale (), new std::codecvt_byname<wchar_t, char, std::mbstate_t>("")));
UPDATE 2
Here is what works for me.
The key is to set the C locale as well. IMHO, this is a bug in GNU C++ standard library implementation. Unless I am mistaken, settingstd::locale::global("");
should also set the C library locale.#include <iostream> #include <locale> #include <clocale> #define DUMP(x) do { std::wcerr << #x ": " << x << "\n"; } while (0) int main(){ using namespace std; std::locale loc (""); std::locale::global (loc); DUMP(std::setlocale(LC_ALL, NULL)); DUMP(std::setlocale(LC_ALL, "")); wcin.imbue (loc); DUMP (wcin.good()); wchar_t aChar = 0; wcin >> aChar; DUMP (wcin.good()); DUMP ((int)aChar); wcout << L"You entered " << aChar << L" .\n"; return 0; }
UPDATE 3
I am confused, now I cannot reproduce it again and setting
std::locale::global(loc);
seems to do the right thing wrt/ the C locale as well.
相关问答
更多-
法语口音的字符编码(Character encoding for French Accents)[2023-04-30]
如果intérêt显示为intérêt 确保标题的格式正确,并将内容呈现为UTF-8编码。 If intérêt shows up as intérêt you likely (i.e. short of corruption due to double encoding) have UTF-8 encoded text being shown up as if it were ISO-8859-1. Make sure the headers are correctly formed and pr ... -
SimpleXML和法语字符(SimpleXML and french characters)[2023-09-12]
我使用此内容在latin1( ISO-8859-1 )中创建了一个名为latin1.xml的特定文件(您可以在xml标记中添加encoding="UTF-8" ,它是相同的):çùé$ °à §çòò àù§ 124 -
wcout是如何工作的?(How does wcout work?)[2022-04-09]
此示例调用未定义的行为。 operator<<(std::wostream&,const wchar_t*)期望缓冲区为空终止,并在到达第一个L'\0'字符时停止打印字符。 如果缓冲区恰好包含空字符( L'\0' ),则代码将“正确”运行(尽管输出是不可预测的)。 如果没有,那么operator<<将继续读取内存直到遇到内存。 您的示例不强制存在空终止符。 相比之下,下面将打印一个未指定数量的字符,很可能是垃圾,但是定义得很好: WCHAR wArray[1024]; wArray[1023] = L'\0 ... -
问题得到解决,对于阿拉伯字符来说这是一个hibernate问题,我必须像这样编辑我的jdbc网址 jdbc:mysql://localhost:3306/pagesjaunes?useUnicode=true&characterEncoding=UTF-8 而且我必须在ajax函数中设置type : 'post' 。 对于ajax调用中的法语字符,我必须将我的js文件类型修改为utf-8 ,右键单击eclipse中的js文件 - >特性。 PS修改后我必须再次检查我的js文件并修复错误的法语字符;) 如果 ...
-
功能IF但用法语(function IF but in French)[2023-10-25]
尝试这个, function si(condition) { return { alors: function(callback) { if (condition) callback(); return this; }, sinon: function(callback) { if (!condition) callback(); return this; ... -
PHP打印法语月份?(PHP print Month in French?)[2023-12-17]
我通常做这样的str_replace (对于德语,因为我不知道新鲜)。 $date = str_replace( array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'), array('Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Jul ... -
首先,添加一些错误检查。 测试输入后wcin.good()返回的内容以及wcout.good()在“你输入”打印后返回的内容是什么? 我怀疑其中一个会返回false 。 您的LANG和LC_*环境变量设置为什么? 然后尝试通过在 main()的顶部添加它来解决这个问题: wcin.imbue(std::locale("")); wcout.imbue(std::locale("")); wcin.imbue(std::locale("")); wcout.imbue(std::locale("")); 我现 ...
-
std::wcout << content; 这实际上是调用std::wostream::operator<<(const wchar_t *) 。 它不知道content不是以␀结尾的字符串。 事实上,它不可能知道它在第一种情况下有效长度为4096而在第二种情况下有一些量(你没有保存fgetswc的返回值)。 std::wcout << content; This is effectively calling std::wostream::operator<<(const wchar_t *). It ...
-
如何打印递增字符(How to print an incrementing character)[2023-06-09]
您在函数generateLetter代码始终打印B 您需要将指示当前步骤的参数传递给函数。 尝试这个: def generateLetter(i): print(chr(ord('A') + i)) def main(): ... for each in range(howMany): generateLetter(each) ... You code in function generateLetter always print B. You n ... -
Python上的法语词典(French Dictionary on Python)[2022-01-23]
为了给你高层次的想法: 您在翻译词典中使用英语单词作为键来获得该单词的法语版本: >>> dictionary_of_words = {"yes":"oui", "no":"non"} >>> dictionary_of_words["yes"] 'oui' >>> 因此,当您读取一个单词作为输入时,检查它是否包含在字典的键列表中,如果是,则打印翻译,否则抛出例外。 要迭代字典,循环键也可以: >>> list_keys = dictionary_of_words.keys() >>> list_keys ...