1

我是 emberjs 的新手,正在制作一个简单的 CRUD 应用程序。我正在使用 ember 数据和localstorage-adapter将记录保存在浏览器的本地存储中。

我正在尝试使用 localstorage-adapter 更新记录,但它抛出错误。

我在这里列出了我的代码:

updatecontact: function(){//save data in local storage
        var fname = this.obj_form_edit_data.get('cont_data.fname');
        var lname = this.get('cont_data.lname');
        var email = this.get('cont_data.email');
        var contactno = this.get('cont_data.contactno');
        var gendertype = ((this.get('isMale') == true) ? true : false);
        var contactype = $(".selectpicker").val();
        Grid.ModalModel.updateRecords({ 
          fname: fname,
          lname: lname,
          email: email,
          contactno: contactno,
          gendertype: gendertype,
          contactype: contactype
        });
        this.get('store').commit();             
    }

使用上面的代码出现以下错误:

Uncaught TypeError: Object function () {
if (!wasApplied) {
  Class.proto(); // prepare prototype...
}
o_defineProperty(this, GUID_KEY, undefinedDescriptor);
o_defineProperty(this, '_super', undefinedDescriptor);
var m = meta(this);
m.proto = this;
if (initMixins) {
  // capture locally so we can clear the closed over variable
  var mixins = initMixins;
  initMixins = null;
  this.reopen.apply(this, mixins);
}
if (initProperties) {
  // capture locally so we can clear the closed over variable
  var props = initProperties;
  initProperties = null;

  var concatenatedProperties = this.concatenatedProperties;

  for (var i = 0, l = props.length; i < l; i++) {
    var properties = props[i];

    Ember.assert("Ember.Object.create no longer supports mixing in other definitions, use createWithMixins instead.", !(properties instanceof Ember.Mixin));

    for (var keyName in properties) {
      if (!properties.hasOwnProperty(keyName)) { continue; }

      var value = properties[keyName],
          IS_BINDING = Ember.IS_BINDING;

      if (IS_BINDING.test(keyName)) {
        var bindings = m.bindings;
        if (!bindings) {
          bindings = m.bindings = {};
        } else if (!m.hasOwnProperty('bindings')) {
          bindings = m.bindings = o_create(m.bindings);
        }
        bindings[keyName] = value;
      }

      var desc = m.descs[keyName];

      Ember.assert("Ember.Object.create no longer supports defining computed properties.", !(value instanceof Ember.ComputedProperty));
      Ember.assert("Ember.Object.create no longer supports defining methods that call _super.", !(typeof value === 'function' && value.toString().indexOf('._super') !== -1));

      if (concatenatedProperties && indexOf(concatenatedProperties, keyName) >= 0) {
        var baseValue = this[keyName];

        if (baseValue) {
          if ('function' === typeof baseValue.concat) {
            value = baseValue.concat(value);
          } else {
            value = Ember.makeArray(baseValue).concat(value);
          }
        } else {
          value = Ember.makeArray(value);
        }
      }

      if (desc) {
        desc.set(this, keyName, value);
      } else {
        if (typeof this.setUnknownProperty === 'function' && !(keyName in this)) {
          this.setUnknownProperty(keyName, value);
        } else if (MANDATORY_SETTER) {
          Ember.defineProperty(this, keyName, null, value); // setup mandatory setter
        } else {
          this[keyName] = value;
        }
      }
    }
  }
}
finishPartial(this, m);
delete m.proto;
finishChains(this);
this.init.apply(this, arguments);

} 没有方法“updateRecords”

我正在使用以下代码创建工作正常的新记录:

savecontact: function(){//save data in local storage
        var fname = this.obj_form_edit_data.get('cont_data.fname');
        var lname = this.obj_form_edit_data.get('cont_data.lname');
        var email = this.obj_form_edit_data.get('cont_data.email');
        var contactno = this.obj_form_edit_data.get('cont_data.contactno');
        var gendertype = ((this.get('isMale') == true) ? true : false);
        var contactype = $(".selectpicker").text();
        Grid.ModalModel.createRecord({  
          fname: fname,
          lname: lname,
          email: email,
          contactno: contactno,
          gendertype: gendertype,
          contactype: contactype
        });
        this.get('store').commit(); 
    }
4

1 回答 1

0

您使用updateRecords复数形式,应该是updateRecord

于 2014-07-31T10:38:31.180 回答