小编Ste*_*evo的帖子

在Jasmine测试中模拟出angular.element

我在一个有呼叫的控制器中有一个功能

var someVar = angular.element(event.target).scope().field;
Run Code Online (Sandbox Code Playgroud)

我试图通过这样做来嘲笑它

var ngElementFake = function(el) {
                return {
                    scope: function() {
                        return {
                            toggleChildElement: true,
                            field: scope.field
                        }
                    }
                }
            }

spyOn(angular, 'element').andCallFake(ngElementFake);
Run Code Online (Sandbox Code Playgroud)

但是,当我在测试中调用该函数时,我得到了响应:

TypeError: 'undefined' is not a function (evaluating 'injector.get('$rootElement').off()')
at ../angular-mocks/angular-mocks.js:1819
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

编辑:注射

    beforeEach(function() {
        inject(function($rootScope, $controller) {

            scope = $rootScope;

            scope.record = recordData;

            scope.model = 'Hierarchy';

            ctrl = $controller("fngHierarchyChildCtrl", {
                $scope: scope
            });
        });
    });
Run Code Online (Sandbox Code Playgroud)

unit-testing jasmine angularjs

14
推荐指数
2
解决办法
1万
查看次数

Angular $ sce阻止我的音频blob src

我试图使用角度ngRepeat与html5音频标签.我有html:

    <li ng-repeat="recordings in recordinglist">
        <audio controls ng-src="{{recordings}}"></audio>
   </li>
Run Code Online (Sandbox Code Playgroud)

和js:

    $scope.$apply($scope.recordinglist.push("blob:http%3A//localhost%3A9000/67ecfa65-3394-45a6-8f29-42f3421a2727"));
Run Code Online (Sandbox Code Playgroud)

但是,角度相同的原点检查会导致插值错误:

Error: [$interpolate:interr] Can't interpolate: {{recordings}}
Error: [$sce:insecurl] Blocked loading resource from url not allowed by $sceDelegate policy.  URL: blob:http%3A//localhost%3A9000/67ecfa65-3394-45a6-8f29-42f3421a2727
Run Code Online (Sandbox Code Playgroud)

这看起来很傻.它不是内插本地资源.我想有一种方法可以正确地做到这一点 - 或者我应该提交错误报告?

javascript audio html5 angularjs

14
推荐指数
1
解决办法
2万
查看次数

VBA - 如何将集合添加到集合集合中

我正在尝试使用Word 2007中的VBA创建代表表单文档的代码.我创建了表示Section,QuestionSet和Question的类.

所以我有15个部分.我创建了一个函数来创建每个'Section'对象将它添加到'Sections'集合然后销毁对象,结果是对象在集合中保持持久性(或者其他东西).

是否可以使用相同的方法将集合添加到集合中,或者我是否必须明确定义每个集合?

模块中的代码:

Public Sections As Collection

Function DefineSection(ByVal SectionName As String)

    Set Section = New clsSection
    Section.myName = SectionName
    Sections.Add Section, SectionName

End Function


Function DefineQuestionSet(ByVal SectionName As String, ByVal Name As String, ByVal NoOfQuestions As Integer, ByVal IsMutuallyExclusive As Boolean, Optional ByVal DependentOnSection As String)

    Dim Qsets As Collection

    Set Qsets = New Collection
    Set QuestionSet = New clsQuestionSet

    QuestionSet.Name = Name
    QuestionSet.NoOfQuestions = NoOfQuestions
    QuestionSet.MutuallyExclusive = IsMutuallyExclusive

    If Not (DependentOnSection) = "" Then
        QuestionSet.DependentOnSection = …
Run Code Online (Sandbox Code Playgroud)

collections excel vba excel-vba word-vba

11
推荐指数
1
解决办法
2万
查看次数

Blueimp jquery文件上传 - 在上下文中进行回调,最后一个不更新

我正在使用:https://github.com/blueimp/jQuery-File-Upload(基本插件,没有添加ui)

我正在使用data.context绑定链接各个节点以更新每个文件上载的进度,但它不会更新最后加载的文件.因此,例如,如果我选择4个文件,它们将显示在我的页面上,进度将适用于列表中的前3个,但不适用于第4个.无论选择哪个数字,它始终是列表中的最后一个.(如果只选择了1个项目,则可以正常工作).

此外,它似乎也没有更新相关的进度条.

有任何想法吗?

这是我的代码:

$('.aws').fileupload({

    limitMultiFileUploads: 1,

    dataType: 'html',

    add: function (e, data) {

            var file = data.files[0];
            var fileDetails = '<tr><td>' + 
            file.name + 
            '</td><td class="progress"><span class="progress"><span class="js-progress-active progress-active"></span>' + 
            '</span></td><td class="cancel-file"><a href="#" class="cancel-file-load-icon js-cancel-file">Cancel</a></td></tr>';

            if ($('.file-list table tr:last').length > 0) {
                data.context = $('.file-list table tr:last').after(fileDetails);
            } else {
                data.context = $(fileDetails).appendTo('.file-list table');
            }

            data.submit();
    },

    progress: function (e, data) {
        var progress = parseInt(data.loaded / data.total * 100, 10);
        data.context.find('.js-progress-active').css(
            'width',
            progress …
Run Code Online (Sandbox Code Playgroud)

jquery file-upload blueimp

7
推荐指数
1
解决办法
5132
查看次数

创建一个多维数组 - 有比这更好的方法

我有这个代码

        foreach ($objWorksheet->getRowIterator() as $row) {

            $output[] = array();

            //adding a blank array to the end doesn't seem to 
            //advance the array pointer so do it manually.
            $test = end($output); 

            $cellIterator = $row->getCellIterator();
            foreach ($cellIterator as $cell) {
                //specifically this bit
                $output[key($output)][] = $cell->getValue();
            }
        }
Run Code Online (Sandbox Code Playgroud)

但我不喜欢我如何使用当前密钥

$output[key($output)][] = $cell->getValue();
Run Code Online (Sandbox Code Playgroud)

有更好的方法吗?

php

1
推荐指数
1
解决办法
166
查看次数

为什么这个主干视图无法正确呈现?

我在backbone.js中有一些观点,我想要成为另一个的孩子.所以我创建了以下代码.

var app = app || {} ;

app.ProjectCardView = Backbone.View.extend({

    el: $('.list'),

    template: _.template( $("#tpl-project-card-summary").html() ),


    initialize: function() {
        this.render();
    },

    render: function() {
        return this.$el.html( this.template() );

    }

});


app.DashboardView = Backbone.View.extend({

    el: $('.contentwrap'),

    template: _.template( $("#tpl-dashboard").html() ),

    initialize: function() {
        this.render();
        this.addProjects();
    },

    render: function() {
        //console.log(this.template());
         this.$el.html( this.template() );

    },

    addProjects: function() {
        var pcv = new app.ProjectCardView();    
    }



});

app.dash = new app.DashboardView;
Run Code Online (Sandbox Code Playgroud)

DashboardView渲染完美,但是当我创建ProjectCardView时,视图似乎没有初始化,因此模板为空并且未设置el.如果我在初始化函数中设置el,则仍然没有设置$ el.我只是看不出我做错了什么.

编辑:看起来我发现了这个问题; $('.list')是第一个视图引入的元素,因此,即使第一个视图已在DOM中呈现,它也不会在第二个视图尝试找到它时呈现.

那么我该如何解决这个问题呢?

backbone.js

1
推荐指数
1
解决办法
520
查看次数