Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/375.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在AngularJS应用程序中的页面加载上执行SharePoint功能($scope issue???)_Javascript_Angularjs_Sharepoint_Sharepoint 2013_Sharepoint Api - Fatal编程技术网

Javascript 在AngularJS应用程序中的页面加载上执行SharePoint功能($scope issue???)

Javascript 在AngularJS应用程序中的页面加载上执行SharePoint功能($scope issue???),javascript,angularjs,sharepoint,sharepoint-2013,sharepoint-api,Javascript,Angularjs,Sharepoint,Sharepoint 2013,Sharepoint Api,我在AngularJS应用程序中使用SharePoint的JavaScript对象模型,需要在页面加载时执行其中一个函数,以便填充数组并由ng repeat使用 当前,它会将数组推送页面加载记录到控制台,但在我单击输入框中的输入/输出、警报框中的单击确定或保持我在页面上的虚拟链接之前,它似乎不会将值提交到数组中以在页面/$scope上使用。这就是我感到困惑的地方,为什么它可以在加载时正确地记录数组,但不能在页面的$scope中准备好数组 我尝试了以下方法,但没有成功: 1) 我已经将执行函数的调

我在AngularJS应用程序中使用SharePoint的JavaScript对象模型,需要在页面加载时执行其中一个函数,以便填充数组并由ng repeat使用

当前,它会将数组推送页面加载记录到控制台,但在我单击输入框中的输入/输出、警报框中的单击确定或保持我在页面上的虚拟链接之前,它似乎不会将值提交到数组中以在页面/$scope上使用。这就是我感到困惑的地方,为什么它可以在加载时正确地记录数组,但不能在页面的$scope中准备好数组

我尝试了以下方法,但没有成功:

1) 我已经将执行函数的调用移到了控制器的底部

2) 我已经尝试了angular.element(文档)。准备好了吗

3) 我已尝试将其包装在函数中,例如:

$scope.initTaxonomy = function () {
        $(function () {
        // Function here
        });
        };
我不明白的是,为什么调用REST服务的以下函数在页面加载时执行/通过将$scope推入ng repeat中使用而完美工作,而我的函数却没有:

 // Array holding items for display on homepage
    $scope.items = [];

    appItems.query(function (result) {
        // Data is within an object of "value", so this pushes the server side array into the $scope array
        var result = result.value;
        var userInfo;

        // Foreach result, push data into items array
        angular.forEach(result, function (resultvalue, resultkey) {

            $scope.items.push({
                title: resultvalue.Title,
                status: resultvalue.Status
             });
        });
    });
此函数将在页面加载时成功登录到控制台,但在我单击页面之前不会在my ng repeat中填充数组:

    var termsArray = [];

    $scope.termsArray = termsArray;

    execOperation();

    function execOperation() {
        //Current Context
        var context = SP.ClientContext.get_current();
        //Current Taxonomy Session
        var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
        //Term Stores
        var termStores = taxSession.get_termStores();
        //Name of the Term Store from which to get the Terms.
        var termStore = termStores.getByName("Taxonomy_1111");
        //GUID of Term Set from which to get the Terms.
        var termSet = termStore.getTermSet("1111111");
        var terms = termSet.getAllTerms();
        context.load(terms);
        context.executeQueryAsync(function () {
            var termEnumerator = terms.getEnumerator();
            while (termEnumerator.moveNext()) {
                var currentTerm = termEnumerator.get_current();
                var guid = currentTerm.get_id();
                var guidString = guid.toString();
                termsArray.push({
                    termName: currentTerm.get_name(),
                    termGUID: guidString,
                });
                //getLabels(guid);
            }
            console.log($scope.termsArray)
        }, function (sender, args) {
            console.log(args.get_message());
        });
       };
我的控制器通过app.js加载页面,如下所示:

$routeProvider.
            when('/', { templateUrl: '/views/home.html', controller: 'appHomeItemsCtrl' }).
            when('/add-item', { templateUrl: '/views/add-item.html', controller: 'appItemPostCtrl' }).
            otherwise({ redirectTo: '/' });  

这是SharePoint的JSOM需要正确执行的问题,我是如何在AngularJS中执行的,还是其他问题

我能让它工作起来。问题是Angular似乎不尊重非Angular函数,因此在将数组推送到$scope时使用$scope.apply是有效的。请注意,包装整个函数会导致Angular摘要出现问题:

    var termsArray = [];

    execOperation();

    function execOperation() {

            //Current Context
            var context = SP.ClientContext.get_current();
            //Current Taxonomy Session
            var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
            //Term Stores
            var termStores = taxSession.get_termStores();
            //Name of the Term Store from which to get the Terms.
            var termStore = termStores.getByName("Taxonomy_1111");
            //GUID of Term Set from which to get the Terms.
            var termSet = termStore.getTermSet("1111");
            var terms = termSet.getAllTerms();
            context.load(terms);
            context.executeQueryAsync(function () {

                var termEnumerator = terms.getEnumerator();
                while (termEnumerator.moveNext()) {
                    var currentTerm = termEnumerator.get_current();
                    var guid = currentTerm.get_id();
                    var guidString = guid.toString();
                    termsArray.push({
                        termName: currentTerm.get_name(),
                        termGUID: guidString,
                    });

                }
                console.log(termsArray)
                $scope.$apply(function () {
                    $scope.termsArray = termsArray;
                });
            }, function (sender, args) {
                console.log(args.get_message());
            });
          };

您是否尝试过使用window.load作为触发器而不是document.ready?还没有。你有一个例子吗?我测试了$window几种方法,但它也不起作用。想知道这是否与SharePoint的上下文有关