Ember.js数组作为模型的属性 [英] Ember.js array as model's property

查看:146
本文介绍了Ember.js数组作为模型的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

干杯!
我有一些模型,它的一个属性是一个数组,但由于某些原因(我在服务器上使用mongoDB,这是嵌入式模型和ember数据的问题)我不能这样做: / p>

Cheers! I have some model, and one attribute of it is an array, but for some reasons (I use mongoDB on the server and it's problem with embedded models and ember-data) I can't do somthing like this:

App.Foo = DS.Model.extend({
  ...
  numbers: DS.hasMany('App.Bar')
)};

App.Bar = DS.Model.extend({
  ...
  number: DS.attr('number')
});

我需要这样的东西:

App.Bar = DS.Model.extend({
  numbers: DS.attr('array')
});

但是,ember数据中没有数组类型的属性,如何?

But there is no array type of attributes in ember-data, how to be?

推荐答案

我发现实际上你可以通过不指定一个类型来开启数组属性。

I found that actually you can have array properties out of the box by just not specifying a type.

#coffeescript

AskuWhiteLabel.SomeModel = DS.Model.extend
    some_ids: DS.attr()

我使用这个,当我这样做

I'm using this, and when I do this

myModel.set('some_ids', [1,2,3])
myModel.save()

服务器的有效载荷确实是我的数组。

The payload to the server is indeed my array as is.

这篇关于Ember.js数组作为模型的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆