为骨干模型中的嵌套属性赋值,但不使用.set方法

时间:2015-12-03 17:30:09

标签: javascript backbone.js

例如,我的默认值为

String d = JOptionPane.showInputDialog("enter start");
int s = Integer.parseInt(d);
String h = JOptionPane.showInputDialog("enter the end");
int z = Integer.parseInt(h);
for (int a = 1 ; a<10 ; a++) { 
    if (a%2 == 0 ) {
        JOptionPane.showMessageDialog(null, a);
        System.out.print(a);
    }
}    

我喜欢在属性下分配权重属性,但不使用.set。我想在实例化期间这样做。

这是对的吗?

defaults: { name: '',
  properties: {
    weight: 0
  }
}

2 个答案:

答案 0 :(得分:1)

不幸的是,它不会工作,你必须将属性作为对象传递。例如:

this.model = new MyModel({name: 'Kenny Rogers', properties: { weight: 195 })

答案 1 :(得分:0)

我使用了你的解决方案加上解析是必需的但我必须包括{parse:true},因为我实例化它。

parse(resp) {
  _.extend(resp.properties, this.defaults.properties);
  return resp
}