这是问题,我有饲料定义,其中包含多对多关系的部分。这意味着,1个Feed定义可以有多个部分,1个部分可以有多个Feed定义。
当我显示费用时,我必须显示与其关联的部分列表。请检查模型中的部分。
如果有人想要删除该关联,我有一个名为section feed的单独模型,它是一个单独的表。因此,在删除操作上,我获取部分提要条目并尝试删除但我收到以下错误。
请让我知道我做错了什么。
错误地点
this.store.find("sectionfeed", {
sectionDefintionID : section.id
feedDefinitionID : feed.id
}).then(function (sectionfeed) {
sectionfeed.deleteRecord(); //is not working. Here I get the error
sectionfeed.save();
});
我可以获取节提要但是在section.deleteRecord上我得到了错误。请参阅下面的完整信息。
设置
DEBUG: -------------------------------
ember.js:14463 DEBUG: Ember : 1.7.0
ember.js:14463 DEBUG: Ember Data : 1.0.0-beta.9
ember.js:14463 DEBUG: Handlebars : 1.3.0
ember.js:14463 DEBUG: jQuery : 2.1.1
ember.js:14463 DEBUG: -------------------------------
模板
<div class="row">
<div class="col-sm-12">
{{go-back}}
</div>
</div>
<br>
<div class="row">
<div class="col-sm-12">
<div class="pull-left lead"> {{displayTitle}} </div>
{{link-to 'Edit' 'feeddefinition.edit' this class="edit-button btn btn-primary btn-sm"}}
</div>
</div>
<br>
<div class="row">
<div class="col-sm-12">
<table class="table table-hover">
<tr>
<td><strong> Id </strong></td>
<td> {{id}} </td>
</tr>
<tr>
<td><strong> Title </strong></td>
<td> {{displayTitle}} </td>
</tr>
<tr>
<td><strong> Url </strong></td>
<td><a {{bind-attr href=url}} target="_blank"> {{url}} </a></td>
</tr>
<tr>
<td><strong> Link </strong></td>
<td><a {{bind-attr href=link}} target="_blank"> {{link}} </a></td>
</tr>
<tr>
<td><strong> Disabled </strong></td>
<td> {{disabled}} </td>
</tr>
<tr>
<td><strong> Created </strong></td>
<td>{{createdAt}}</td>
</tr>
<tr>
<td><strong> Last Modified </strong></td>
<td> {{modifiedAt}} </td>
</tr>
<tr>
<div class="col-sm-12">
<table class="table table-bordered table-hover channels">
<thead>
<th> Name</th>
<th> Created</th>
<th> Modified</th>
<th> Updated</th>
<th> Liverpooled</th>
</thead>
<tbody>
{{#each section in model.sections}}
<tr>
<td> {{#link-to 'section' section}}{{section.name}}{{/link-to}} </td>
<td> {{fromNow section.createdAt}} </td>
<td> {{fromNow section.modifiedAt}} </td>
<td> {{fromNow section.updatedAt}} </td>
<td> {{fromNow section.liverpooledAt}} </td>
<td>
<button class="btn btn-primary btn-sm" {{action 'remove' model section}}>Remove</button>
</td>
</tr>
{{ else }}
<tr>
<td colspan="5">
No Section found.
</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
</tr>
</table>
</div>
</div>
包含部分
的Feed定义模型/*global Ember*/
Backoffice.Feeddefinition = DS.Model.extend({
createdAt: DS.attr('date'),
modifiedAt: DS.attr('date'),
url: DS.attr('string'),
type: DS.attr('string'),
link: DS.attr('string'),
title: DS.attr('string'),
disabled: DS.attr('boolean'),
automaticallyAdded: DS.attr('boolean'),
userAdded: DS.attr('boolean'),
sections: DS.hasMany('sections', {async: true}),
displayTitle: function () {
return this.get('title') === '' ? 'No Title' : this.get('title');
}.property('title')
});
// probably should be mixed-in...
Backoffice.Feeddefinition.reopen({
attributes: function () {
var model = this;
return Ember.keys(this.get('data')).map(function (key) {
return Em.Object.create({ model: model, key: key, valueBinding: 'model.' + key });
});
}.property()
});
节进给模型 - 进料和节之间的多对多关系
/ 全球Ember /
Backoffice.Sectionfeed = DS.Model.extend({
sectionDefinitionID: DS.attr('string'),
feedDefinitionID: DS.attr('string')
});
Feed的路由器
Backoffice.FeeddefinitionRoute = Ember.Route.extend({
model: function (params) {
return this.get('store').find('feeddefinition', params.feeddefinition_id);
},
actions: {
remove: function (feed, section) {
var model = this.model;
this.store.find("sectionfeed", {
sectionDefintionID : section.id
feedDefinitionID : feed.id
}).then(function (sectionfeed) {
sectionfeed.deleteRecord(); //is not working. Here I get the error
sectionfeed.save();
});
}
}
});
错误
ember.js:14463 TypeError: undefined is not a function
at http://localhost:9000/scripts/combined-scripts.js:1492:33
at tryCatch (http://localhost:9000/bower_components/ember/ember.js:45818:16)
at invokeCallback (http://localhost:9000/bower_components/ember/ember.js:45830:17)
at publish (http://localhost:9000/bower_components/ember/ember.js:45801:11)
at http://localhost:9000/bower_components/ember/ember.js:29069:9
at DeferredActionQueues.invoke (http://localhost:9000/bower_components/ember/ember.js:634:18)
at Object.DeferredActionQueues.flush (http://localhost:9000/bower_components/ember/ember.js:684:15)
at Object.Backburner.end (http://localhost:9000/bower_components/ember/ember.js:147:27)
at Object.Backburner.run (http://localhost:9000/bower_components/ember/ember.js:202:20)
at apply (http://localhost:9000/bower_components/ember/ember.js:18382:27)
ember.js:3722 Uncaught Error: Assertion Failed: TypeError: undefined is not a function
REST API是用java编写的。以下是端点
@RequestMapping(value = "/sectionfeeds", method = {RequestMethod.DELETE})
public void remove(@RequestBody String body) throws Exception {
JsonNode jsonNode = objectMapper.readTree(body);
SectionFeed sectionFeed = objectMapper.reader(SectionFeed.class).readValue(jsonNode.get("sectionfeed"));
sectionFeedManager.remove(sectionFeed.getSectionDefinitionID(), sectionFeed.getFeedDefinitionID());
}
Finder方法
@RequestMapping(value = "/sectionfeeds", method = {RequestMethod.GET})
public @ResponseBody
Map<String, Object> get(@RequestParam(value = "sectionDefinitionID", required = true) String sectionDefinitionId,
@RequestParam(value = "feedDefinitionID", required = true) String feedDefinitionId) throws Exception {
System.out.println(sectionDefinitionId);
System.out.println(feedDefinitionId);
SectionFeed sectionFeed = sectionFeedManager.find(UUID.fromString(sectionDefinitionId),
UUID.fromString(feedDefinitionId));
return createReturnMap("sectionfeed",sectionFeed, null);
}
从下面的评论中,我做了更改
actions: {
remove: function (feed, section) {
var model = this.model;
var sectionfeed = this.store.find("sectionfeed", {
sectionDefinitionID:section.id,
feedDefinitionID : feed.id
});
var sfeed = sectionfeed.get("sectionfeed");
sfeed.deleteRecord();
sfeed.save();
}
}
之后我得到了#34; Uncaught TypeError:无法读取属性&#39; deleteRecord&#39;未定义&#34;。
答案 0 :(得分:0)
我认为这可能是因为您对商店的查询返回了一个数组。 as per the docs
如果您提供普通对象作为查找的第二个参数,Ember 数据将生成一个GET请求,并将对象序列化为查询 PARAMS。此方法以与find相同的方式返回DS.PromiseArray 没有第二个论点。
例如,我们可以搜索具有该名称的所有人物模型 彼得:
var peters = this.store.find('person', { name: "Peter" }); // => GET to /persons?name='Peter
如果检查它是否返回一个数组,而不是一个对象,然后调用该数组中第一个对象的deleteRecord()