似乎没有考虑我的 Coffeescript 验证:
class PokerRange extends Backbone.Model
defaults:
id:0
cards:[[0..12],[0..12],[0..12],[0..12],[0..12],[0..12],[0..12],[0..12],[0..12],[0..12],[0..12],[0..12],[0..12]]
validate: (attributes) ->
if attributes.id<0 then "id should be positive"
window.firstrange= new PokerRange id:5
console.log window.firstrange.toJSON()
window.firstrange.set("id",-4)
console.log window.firstrange.toJSON()
这是结果:
Object {id: 5, cards: Array[13]}
Object {id: -4, cards: Array[13]}