繁体   English   中英

灰烬js:deleteRecord TypeError:未定义不是函数

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM