我使用这个代码的CoffeeScript:参数为骨干视图渲染方法
在SPEC文件:
index = new MeetingIndex(render: false, collection: booking.meetings)
index.render(writeTo: '.sandbox')
在视图文件
:
render: (options = {}) ->
console.log 'options'
console.log options
console.log 'options'
options[key] ||= val for key, val of writeTo: 'body', enhanceUI: true
浏览器控制台打印:
Object
enhanceUI: true
writeTo: "body"
what coul这里会发生什么?我怎样才能传递参数来渲染方法?
意识到这一点'选项[关键] || = val'。如果你传递'enhanceUI:false',它将被重写为'true'。如果你不想这样做,你可以把它改成'options [key]?= val' :) – epidemian