[英]Ember js : deleteRecord TypeError: undefined is not a function
這是問題所在,我有feed定義,其中的部分具有多對多關系。 也就是說,1個提要定義可以具有多個部分,而1個提要可以具有多個提要定義。
當我顯示費用時,我必須顯示與之關聯的部分的列表。 請檢查模型中的各個部分。
如果有人想刪除該關聯,那么我有一個名為section feed的單獨模型,它是一個單獨的表。 因此,在執行刪除操作時,我獲取了部分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()
});
分段Feed的模型-分段與Feed之間的多對多關系
/ 全球灰燼 /
Backoffice.Sectionfeed = DS.Model.extend({
sectionDefinitionID: DS.attr('string'),
feedDefinitionID: DS.attr('string')
});
飼料路由器
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());
}
查找器方法
@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();
}
}
之后,我得到“ Uncaught TypeError:無法讀取未定義的屬性'deleteRecord'”。
我認為這可能是因為您對商店的查詢返回了一個數組。 根據文檔
如果提供普通對象作為要查找的第二個參數,則Ember Data將發出GET請求,並將該對象序列化為查詢參數。 此方法以與沒有第二個參數的find相同的方式返回DS.PromiseArray。
例如,我們可以搜索所有名稱為Peter的人模型:
var peters = this.store.find('person', { name: "Peter" }); // => GET to /persons?name='Peter
如果檢查它是否返回一個數組,而不是一個對象,然后在該數組中的第一個對象上調用deleteRecord()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.