{Nativescript}在模型中添加更多属性

时间:2016-08-28 13:50:25

标签: nativescript

我是nativescript的新手。目前我正在我的customer-view-model.js中创建具有2个属性的app,如下所示,并且运行良好。

function Customer( nama ) {
  this.nama = nama;      
  this.complete = false;
}    
module.exports = Customer;

当我添加更多属性(如下面的代码)时,我的应用程序抛出错误消息ReferenceError: telpon is not defined

function Customer( nama ) {
  this.nama = nama;      
  this.telpon = telpon;
  this.complete = false;
}    
module.exports = Customer;

我不知道我错过了什么。请帮助:)

1 个答案:

答案 0 :(得分:1)

你从第一行的参数获得了“nama”,这就是为什么第一个好但不是telpon,所以如果它的输入参数需要添加第一行(作为定义)或者使用函数内的3行来设置变量某个默认值

this.something是模型的属性, this.telpon已经完成了,但是您将变量分配给未定义的属性

function Customer( nama,telpon ) {
  this.nama = nama;      
  this.telpon = telpon;
      //this.telpon = 1; 
      //this.telpon = "string"; 
      //this.telpon = false/true; 
  this.complete = false;
}    
module.exports = Customer;