鉴于此Backbone集合
define [
'underscore',
'backbone',
'cs!models/floor'
], ( _, Backbone, Floor ) ->
return Backbone.Collection.extend
model: Floor
url: ->
return '/api/hotels/' + @hotelId + '/floors'
initialize: (models, options) ->
if ( options.hotelId )
@hotelId = options.hotelId
@.fetch()
parse: (response) ->
response.floors
alreadyExist: ->
@.filter( (floor) ->
return floor.get('number') == @.attrs.get('number')
)
Run Code Online (Sandbox Code Playgroud)
并从下面的视图添加新模型,如何验证模型是否已存在于集合中?
add_floor: (e) ->
console.log ' Saving Floor '
e.preventDefault()
floorNumber = $('input[name=floorNumber]').val()
floorDescription = $('input[name=floorDescription]').val()
return new NoticeView({ message: "Please enter a Floor Number.", displayLength: 10000 }) unless …
Run Code Online (Sandbox Code Playgroud) 有没有人有使用Backbone.js和Pylons/Pyramid的经验?任何样品要看?