【问题标题】:How to resolve angular ng-options track by deep clone issue?如何通过深度克隆问题解决角度 ng-options 跟踪?
【发布时间】:2016-02-25 05:13:49
【问题描述】:

ng-options="branch as branch.name for branch in ordersItemClientInfo.branches track by branch.id"

在我的例子中,“分支”是一个对象数组,每个对象都有指向如此深对象(地图 geoObject)的字段引用。 Angular 试图复制那个对象但失败了!

来自 angular.js:

getViewValueFromOption: function(option) {
  // If the viewValue could be an object that may be mutated by the application,
  // we need to make a copy and not return the reference to the value on the option.
  return trackBy ? angular.copy(option.viewValue) : option.viewValue;
}

我不需要副本,我需要选择原始对象。我怎样才能做到?

【问题讨论】:

  • 我有解决方法(使用 ng-repeat 并按 $index 选择),但不清楚...

标签: angularjs ng-options angularjs-track-by


【解决方案1】:

也许你可以尝试做一个JSON.stringify(在显示之前对每个项目),然后在你想显示的时候在模板中创建JSON.parse

【讨论】:

  • 它会抛出 JSON stringify 错误,因为对象太深了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-30
  • 2023-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-01
相关资源
最近更新 更多