1

如何将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

所以没有一个技巧对我有用,我需要帮助解决这个问题。

4

2 回答 2

0

1)您将验证事物绑定到视图,而不是用户,这就是您收到第一个错误的原因

2)您不应该在模型内部创建视图,

于 2012-10-19T08:17:45.193 回答
0

你应该把backbone.validation.js 放在vendor/scripts 文件夹中。您是否看到必须在插件之前取消 Backbone 和 Underscore?

早午餐适用于配置文件,您应该在 config.coffee 中包含以下内容:

exports.config =
  # See docs at http://brunch.readthedocs.org/en/latest/config.html.

  # Edit the next line to change default build path.
  paths:
    public: 'public'

  files:
    javascripts:
      # Defines what file will be generated with `brunch generate`.
      defaultExtension: 'coffee'
      # Describes how files will be compiled & joined together.
      # Available formats:
      # * 'outputFilePath'
      # * map of ('outputFilePath': /regExp that matches input path/)
      # * map of ('outputFilePath': function that takes input path)
      joinTo:
        'javascripts/vendor.js': /^vendor/
        'javascripts/app.js': /^app/
      # Defines compilation order.
      # `vendor` files will be compiled before other ones
      # even if they are not present here.
      order:
        before: [
          'vendor/scripts/console-helper.js',
          'vendor/scripts/jquery-1.7.2.js',
          'vendor/scripts/underscore-1.3.3.js',
          'vendor/scripts/backbone-0.9.2.js'
          'vendor/scripts/backbone.validation.js'
        ]

重要的是订单部分。

于 2012-05-15T09:54:12.817 回答