如何将http://thedersen.github.com/backbone.validation/与 brunch.io 集成我尝试将骨干网.validation.js 放在供应商文件夹中并
View = require './view'
template = require './templates/home'
User = require 'models/user'
module.exports = class HomeView extends View
id: 'home-view'
template: template
initialize: ->
Backbone.Validation.bind(this)
@user = new User
console.log @user
@user.validate()
给出错误 Uncaught TypeError: Object # has no method 'validate'
然后我也试过了
# The application bootstrapper.
Application =
initialize: ->
HomeView = require 'views/home_view'
Router = require 'lib/router'
User = require 'models/user'
# Ideally, initialized classes should be kept in controllers & mediator.
# If you're making big webapp, here's more sophisticated skeleton
# https://github.com/paulmillr/brunch-with-chaplin
@homeView = new HomeView model: new User
# Instantiate the router
@router = new Router()
# Freeze the object
Object.freeze? this
module.exports = Application
这也是
Model = require './model'
HomeView = require 'views/home_view'
module.exports = class User extends Model
defaults:
logged_in: false,
token: false
initialize: ->
new HomeView model: new User
validation:
email: {
required: true,
pattern: 'email',
msg: 'Please enter a valid email' },
name: {
required: true,
msg: "Name is required" }
给出错误 Uncaught RangeError: Maximum call stack size exceeded
所以没有一个技巧对我有用,我需要帮助解决这个问题。