当前位置: 动力学知识库 > 问答 > 编程问答 >

ember.js - Ember Data not sending to server

问题描述:

I have the following code:

app/models/account.js:

import DS from 'ember-data';

export default DS.Model.extend({

username: DS.attr('string'),

birthdate: DS.attr('date'),

gender: DS.attr('boolean'),

emailaddresses: DS.attr()

});

and app/components/account-profile.js:

import Ember from 'ember';

export default Ember.Component.extend({

buttonLabel: 'Send to Server',

actions: {

buttonClicked(param) {

this.sendAction('action', param);

}

}

});

and app/templates/components/account-profile.hbs

<div class="box">

<div class="title">Your Profile</div>

<div>Username: {{account.accountprofile.username}}</div>

<div>Email Address: {{account.accountprofile.emailaddresses.0.emailaddress}}</div>

<div>Birthdate: {{account.accountprofile.birthdate}}</div>

<div>Gender: {{account.accountprofile.gender}}</div>

</div>

<div>

<div>

<label>Username</label>

<div>

{{input type="text" value=account.accountprofile.username }}

</div>

<label>Username</label>

<div>

{{input type="text" value=account.accountprofile.emailaddresses.0.emailaddress }}

</div>

<label>Username</label>

<div>

{{input type="text" value=account.accountprofile.birthdate }}

</div>

<label>Username</label>

<div>

{{input type="text" value=account.accountprofile.gender }}

</div>

<div>

<div>

<button type="submit" {{action 'buttonClicked' account}}>{{buttonLabel}}</button>

</div>

</div>

</div>

</div>

I do not see any traffic being sent from from my web browser to my server.

What is missing and what's wrong with my code? What other things I need to do?

网友答案:

Refer Persisting Records in ember guides

Records in Ember Data are persisted on a per-instance basis. Call save() on any instance of DS.Model and it will make a network request.

You need to call save method from the record account.accountprofile like this this.get('account.accountprofile').save()

网友答案:

sendAction does not send something to the server.

See https://guides.emberjs.com/v1.10.0/components/sending-actions-from-components-to-your-application/

So try param.save() to save your model for example.

分享给朋友:
您可能感兴趣的文章:
随机阅读: