如何从函数内部的.forEach内部完全退出

时间:2016-06-11 12:29:01

标签: javascript angularjs

我有这个方法:

    wordFormDirty = (): boolean => {
    var self = this;
    angular.forEach(self.word.wordForms, function (wf, key) {
        var wordFormNgForm = 'wordFormNgForm_' + wf.wordFormId
        if (!self[wordFormNgForm].$pristine) {
            return true;
        }
    });
    return false;
};

从我看来,这永远不会回归真实。有人可以给我建议如何实现这一点,以便一个不是原始的表单将使wordFormDirty()方法返回true。

2 个答案:

答案 0 :(得分:1)

如果您希望直接从步行Console.WriteLine("--------------------"); Console.WriteLine("---LOGIN TERMINAL---"); Console.WriteLine("--------------------"); System.Threading.Thread.Sleep(1000); Console.WriteLine("/Log In"); Console.WriteLine("/Create New User"); Console.WriteLine("/Delete User"); var userInput = Convert.ToString(Console.ReadLine()); if(userInput == "Log In") // input check here { Console.WriteLine("Enter User Name"); var userName = Console.ReadLine(); Console.WriteLine("Enter User Password:"); var password = Console.ReadLine(); Console.WriteLine("User Name: {0}, Password: {1}", userName, password); } 获得结果,请考虑使用除Array之外的其他方法。 E.g:

forEach

答案 1 :(得分:1)

你可以尝试这个,在这种情况下,如果我没有解决问题,第一次有一个值为true,结果设置为true,否则它仍为假

wordFormDirty = (): boolean => {
    var self = this;
    var result = false;
    angular.forEach(self.word.wordForms, function (wf, key) {
        var wordFormNgForm = 'wordFormNgForm_' + wf.wordFormId
        if (!self[wordFormNgForm].$pristine) {
            result = true;
        }

    });
    return result;
};
相关问题