javascript – backbone.js model.set无效

前端之家收集整理的这篇文章主要介绍了javascript – backbone.js model.set无效前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用backbone.js model.set属性.第二个警报功能应在实现todo1.set后触发.但事实并非如此.
这是jsfiddle链接http://jsfiddle.net/SGEkn/
var Todo = Backbone.Model.extend({
        defaults: {
            title: "Harsh",completed: false
        },initialize: function() {
            console.log('This model has been initialized.')
        }
    });

var todo2 = new Todo({
    title: 'Set through instantiation.',completed: true
});
console.log('Todo title: ' + todo2.get('title'));
console.log('Todo completed ' + todo2.get('completed'));

alert("ok");

todo2.set("title",'Title set');

alert("ok");

console.log(todo2.get('title'));
todo.set("completed",false);

console.log('completed: ' + todo2.get('completed'));

解决方法

您应该单独传递一个对象而不是参数.
todo2.set({"title":'Title set'});
原文链接:https://www.f2er.com/js/155963.html

猜你在找的JavaScript相关文章