问题标签 [js-data-angular]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
280 浏览

angularjs - js-data-angular 模型中的单元测试承诺

我们在我们的项目中使用js-data和。js-data-angular

我有以下模型:

以及对所述模型的以下调用:

在我的单元测试中,我像这样模拟调用:

并且实际调用是模拟的,什么没有被执行(我找不到任何关于如何完成这个的可靠信息)是里面的.then函数Diagnosis.findAll

我知道代码有效,但我需要用单元测试来覆盖它,而且我快干了。

谢谢。

0 投票
1 回答
231 浏览

jsdata - 如何让 find() 接受一个数组而不是一个对象?

在 Angular 中使用 JS-Data 2.6,我正在尝试使用干净的 URL 加载数据数组,例如 /report/22。(这种格式很有意义,因为它遵循业务逻辑 - 我正在按类别 id 加载报告数据,并返回几行。)

然而,

  • 当我使用 时find,js-data 会因可怕而死,[Error] "attrs" must be an object!因为它需要 1 行,否则无法被说服——除非我遗漏了一些东西。
  • 当我使用时findAll,我需要使用 uglier 进行搜索/report/?categoryId = 22- 并更改服务器
  • 当我使用动作时,它会将动作名称附加到我不需要的 URI 中,例如/report/22/myaction

有什么方法可以使用 find() 或 findAll()

  • 有一个干净的网址
  • 加载数据数组
  • 最好不要更改服务器实现
0 投票
1 回答
889 浏览

angularjs - JS-Data 错误:attrs 必须包含 idAttribute 指定的属性 - 具有 hasMany 关系

这是错误: http: //puu.sh/lXzja/f773fb6c9a.png

我的用户模型的主键是用户名。我的路线的主键是路线名称。我的 api 根据 jsonapi.org 规范在 data:{} 中返回 jsons。因此 id 属性不在顶层,正如 js-data 所要求的那样。这就是我在 afterFind 中为“用户”返回 data.data 的原因。我试图在“路线”中做类似的事情,但它是一系列路线。控制台登录 beforeInject 给了我:

导致 beforeInject

这是配置:

这是我尝试加载路线但出错的地方:

0 投票
1 回答
105 浏览

angularjs - JS-Data loads data but doesn't render in view

I have followed the js-data angular tutorial to setup js-data-angular in my current project.

model definition:

In my controller:

In my view i attempt to iterate over the returned object using ng-repeat but nothing is displayed. I know that my endpoint is hit and data is returned because my console displays the returned shipment object.

The tutorial mentions how to load data into the views but looks to be for those using ngRoute. I am using ui-router in my current project and ran into more challenges when I tried to resolve that resource in that state.

That resource is used in a view that is included in another view - the template view for the state.

Just looking for some direction on how to get my data to display in my view please and thank you in advance.

Revised shipment model:

0 投票
1 回答
125 浏览

jsdata - 如何推送到 js-data 资源中的数组

我有一个包含许多路由对象的用户对象。

我像这样加载它们:

我的用户对象看起来像: 这个

我希望能够去 user.routes.push(newRoute) 然后保存用户。但我无法推出新路线。

0 投票
1 回答
77 浏览

angularjs - 使用 jsdata 对象而不持久化它们

我正在使用 js-data 和 js-data-angular。我有 2 个资源organizationaddress一个组织hasOne地址。

我正在尝试创建一个组织(不持久化)以便能够将其绑定到 html 组件。并设置一些默认道具。所以我在做:

然后我在视图中做类似的事情

<input ng-model="organization.address.country.name">

但是地址没有被设置为组织,因为它在商店中还不存在。那么有什么办法可以解决这个问题吗?

谢谢!

0 投票
1 回答
186 浏览

angularjs - JSData 对象属性导致无限循环

我有一个需要像这样在后端表示的数据属性

然而,角度材料日期选择器需要一个日期对象。所以我认为我将只使用一个属性。但是,当我创建一个属性时,它会导致无限递归。

我的 JSData 模型看起来像这样。

我的 HTML 看起来像这样。博客是一个博客对象。

它会导致此错误。

有谁知道如何解决这一问题?谢谢!

0 投票
1 回答
95 浏览

jsdata - Resources not referencing the same related resource

I've defined two resources - Foo and Bar - where Foo contains one Bar. However, when inserting some basic data in this format, if multiple Foo's reference the same Bar, then only the most recently loaded Foo is given a reference to it. Previous Foo's have no Bar (it is undefined.)

The resources are defined like so:

And I am injecting the following test data:

Why does the first Foo not have a reference to the same Bar as the second Foo?

Fiddle with Jasmine tests here: http://jsfiddle.net/dimmreaper/c0o1kqd0/

0 投票
1 回答
82 浏览

ruby-on-rails - JSData: Sometimes resources are accessed nested under parent resource, and other times not. How is this determined?

I am integrating with an api that exposes child resources nested under parent resources.

This seems to work fine when I am finding or creating resources from JSData, however, updates and deletes seem to want to access the resource directly.

But, with delete and put requests:

It seems like if there is a object id involved for the child record then the url that is constructed is constructed at the base level of the API, and if there is no object id, as is the case with POST and GET (findAll).

Is there something very obvious that I am missing here?

0 投票
1 回答
44 浏览

javascript - js-data:DS“reapAction”配置选项的“none”和“inject”有什么区别?

我有以下定义:

  • "none"- 没做什么
  • "inject"- 将项目重新注入数据存储

上述定义取自官方文档。我不明白将物品重新注入 DS 有什么意义?对于资源的消费者来说,它与什么都不做有什么不同?

第一印象,我认为重新注入会更新lastModified时间戳,但事实并非如此,正如通过运行示例应用程序所验证的那样。