我如何通过属性来一个骨干看法? [英] How do I pass properties to a Backbone view?

查看:97
本文介绍了我如何通过属性来一个骨干看法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是开发利用骨干V1.0.0我的应用程序之间开始工作,现在已经更新到V1.1.0。那么,我曾经是能够做到的,

I was developing my app using Backbone v1.0.0 and between beginning work and now there has been an update to v1.1.0. So where I used to be able to do,

var myView = new MyView({hash: 'something'});

和访问视图内使用,

this.options.hash

这不再起作用。我现在得到以下错误:

This no longer works. I now get the following error:

遗漏的类型错误:无法读取的未定义的属性哈希

Uncaught TypeError: Cannot read property 'hash' of undefined

那么,这样做的新途径?我非常希望能够将属性传递到我的看法。

So what's the new way of doing this? I would very much like to be able to pass properties into my view.

推荐答案

1.1.0更新日志


      
  • 骨干浏览不再自动连接传递给构造选项 this.options ,但你可以,如果你自己做preFER。

  •   
  • Backbone Views no longer automatically attach options passed to the constructor as this.options, but you can do it yourself if you prefer.

所以构造选项仍然传递到初始化,但 this.options 不再自动设置。你可以这样做:

So the constructor options are still passed to initialize but this.options is no longer automatically set up. You can do this:

initialize: function(options) {
    // Stash `options.hash` in `this` if you want or
    // `this.options = options;` if you want to emulate
    // the old behavior.
}

演示: http://jsfiddle.net/ambiguous/SaJkz/

这篇关于我如何通过属性来一个骨干看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆