【问题标题】:How to use embedded_lists with ng_admin (t.map is not a function )如何将 embedded_lists 与 ng_admin 一起使用(t.map 不是函数)
【发布时间】:2016-03-08 12:04:35
【问题描述】:

我正在尝试让我的 REST api 公开我的 mongodb 数据库以连接到 ng-admin。我的成功有限,一旦我将它们从对象转换为字符串,我就可以在界面中看到 _id。

具体来说,我在使用 embedded_list 字段类型来显示子标签时遇到问题。我正在关注文档,但我得到了错误

TypeError: t.map 不是函数

在 Function.i.value (http://172.28.128.3/bower_components/ng-admin/build/ng-admin.min.js:1:5980) [截断...]

在 ae (http://172.28.128.3/bower_components/ng-admin/build/ng-admin.min.js:23:3751)

<ma-embedded-list-column field="::field" value="::value" datastore="::datastore" class="ng-scope ng-isolate-scope">

我的 ng_admin 配置看起来像

var myApp = angular.module('myApp', ['ng-admin']);
myApp.config(['NgAdminConfigurationProvider', function (nga) {
    // create an admin application
    var admin = nga.application('Keyword admin')
      .baseApiUrl('http://172.28.128.3/dictionary/'); // main API endpoint

    var keyword = nga.entity('keyword');
    // set the fields of the user entity list view
    keyword.listView().fields([
        nga.field('_id'),
        nga.field('labels', 'embedded_list') // Define a 1-N relationship with the (embedded) comment entity
        .targetFields([ // which comment fields to display in the datagrid / form
            //nga.field('sport'),
            nga.field('project'),
            nga.field('label')
        ])
    ]);

    //keyword.identifier(nga.field('_id.$id'));
    keyword.identifier(nga.field('_id'));

    admin.addEntity(keyword)
    nga.configure(admin);
}]);

我的 api 的输出看起来像 (url /dictionary/keyword/56dd780e1163cf0d008b4568)

{
  "_id": {
    "$id": "56dd780e1163cf0d008b4568"
  },
  "labels": [
    {
      "label": "the pyramid front left",
      "project": "core"
    }
  ],
  "_links": {
    "self": {
      "href": "http://172.28.128.3/dictionary/keyword/56dd780e1163cf0d008b4568"
     }
  } 
}

【问题讨论】:

    标签: angularjs restangular ng-admin


    【解决方案1】:

    这里的问题是 $labels 不是一个数组,我在 mongodb 聚合函数中做了一个 $unwind 并且在返回数据之前没有撤消它。

    【讨论】:

      猜你喜欢
      • 2018-12-31
      • 2017-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-12
      • 2011-01-15
      • 1970-01-01
      相关资源
      最近更新 更多