将BreezeJS与AngularJS一起使用时出错

Kee*_*jan 1 angularjs breeze

将BreezeJS与AngularJS一起使用会产生错误.例如,在ng-repeat中使用'filter'时,控制台会报告:堆栈空间不足.

重现步骤

  1. 参加Todo-Angular BreezeJS样本并在VS 2012中打开.
  2. 在index.html之前添加 <ul>


    <div>
    <input ng-model="query" type="search" placeholder="search" />
    </div>

Run Code Online (Sandbox Code Playgroud)
  1. 将以下代码添加到li元素的data-ng-repeat中


    <li data-ng-repeat="item in items | filter:query">

Run Code Online (Sandbox Code Playgroud)

过滤器:查询应根据输入中的文本过滤列表,但不会.在IE 10中,控制台报告"用完堆栈空间".在Chrome中,控制台报告"范围错误":

(anonymous function) angular.js:5582
(anonymous function) angular.js:4679
Scope.$digest angular.js:7739
Scope.$apply angular.js:7926
listener angular.js:11228
v.event.dispatch jquery-1.8.3.min.js:2
o.handle.u
Run Code Online (Sandbox Code Playgroud)

当你使用angular.copy(src,dest); 其中src是由BreezeJS创建的,我看到另一个stack_overflow错误.

War*_*ard 8

这是行不通的,因为你要求Angular将搜索文本与TodoItem的每个属性相匹配.

一个Breeze实体的属性包括entityAspect一个被调用的属性,该属性entity指向TodoItem实例......并且在你周围堆栈溢出(双关语).

您需要使用进行特定比较的过滤器函数.试试这个:

Index.html中

<div>
  <input data-ng-model="searchText" type="Search" placeholder="search" />
</div>
<ul>
    <li data-ng-repeat="item in items | filter:itemFilter">
    ... etc. ...

controller.js中

$scope.searchText = "";

// Beware: this is called a lot!
$scope.itemFilter = function (todoItem) {
    var searchText = $scope.searchText;
    // if there is search text, look for it in the description; else return true
    return searchText ?
        -1 != todoItem.Description.toLowerCase().indexOf(searchText.toLowerCase()) :
        true;
};

像我的机器上的魅力一样工作:)

ps:你的事故angular.copy()也有同样的原因......它确实每个属性和实体的深度副本都有循环引用.