错误:steal.js INFO:Model.js - undefined destroy我在CanJS中调用destroy()函数

时间:2016-04-02 08:03:10

标签: javascript ejs canjs

我有一个例子,当我调用destroy函数时,它会删除项目,但是当我刷新浏览器时,它似乎没有删除数据到数据库。

Musics = can.Control({
        init : function(element, options) {
            var el = this.element;
            Music.findAll({}, function(musics) {
                el.html(can.view('view/listMusic.ejs', {
                    musics : musics
                }))
            }, function(error) {
                console.log("Erro:" + error)
            });
        },

        "#add-btn click" : function() {
            can.route.attr({route:"update",type:"add"});
        },
        ".btn-edit click" : function(li) {
            can.route.attr({route:"update/:type",type:"edit",id:""+li.val()+""});
        },
        ".btn-delete click" : function(li) {
           li.closest('tr').data('music').destroy();
        },
  })

文件listMusic.ejs:

<tbody class="tbody-music">
                <% list(musics, function(music){ %>
                    <tr <%= (el)-> el.data('music', music) %>>
                        <td class="col-md-1 col-checkbox">
                            <input type="checkbox">
                        </td>
                        <td class="col-md-5">
                            <%= music.musicName %>
                        </td>
                        <td class="col-md-3">
                            <%= music.musicGenre %>
                        </td>
                        <td class="col-md-3 col-edit">
                            <button class="btn-edit" value="<%= music.musicId %>"><i class="fa fa-pencil"></i></button>
                            <button class="btn-delete" value="<%= music.musicId %>"><i class="fa fa-times"></i></button>
                        </td>
                    </tr>
                <% }) %>
            </tbody>

File Model.js:

steal("jquery", "can", function() {
Music = can.Model({
    findAll : 'GET /api',
    findOne : 'GET /api/{id}',
    destroy : "DELETE /api/{id}",
}, {})

})

然后,我如何在CanJS中使用销毁功能?我这样做是为了联系经理 这是链接:http://ilearnhub.in/tutorials/canjs/contactManager

0 个答案:

没有答案