在Nativescript 2.2.0更新

时间:2016-08-10 22:36:39

标签: android nativescript

我刚刚更新到Nativescript 2.2.0,一切都很好,并且在我的大多数应用程序中运行良好。加载特定视图时,虽然我得到了下面未处理的异常以及堆栈跟踪。在更新核心平台和模块之前没有发生这种情况。当我搜索' disableNotifications'堆栈跟踪中提到的属性我在项目中找不到任何类型。做了一些挖掘似乎是核心框架的一些地方,任何机构有什么想法?

编辑:这是核心可观察模块中发生错误的实际代码块。他们是否已按照以下方式删除了添加属性的功能var model = new Observable({propName: 'value'});

Observable.js code where exception is thrown:
    Observable.prototype._setCore = function (data) {
        this.disableNotifications[data.propertyName] = true;
        var newValue = WrappedValue.unwrap(data.value);
        this[data.propertyName] = newValue;
        delete this.disableNotifications[data.propertyName];
    };

以下是我倾向于在视图模型中实例化我的Observable:

var model = new Observable({
    measurements: new ObservableArray([]),
    recentMeasurement: {},
    notificationsEnabled: appSettings.getBoolean('notificationsEnabled', true),
    patientFirstName: "",
    patientLastName: "",
    units: "",
    hasMultipleConnections: true
});

另一个例子

var model = new Observable({        
    countries:  new ValueList([
        { ValueMember: "FR", DisplayMember: L('france') },
        { ValueMember: "DE", DisplayMember: L('germany') },
        { ValueMember: "IT", DisplayMember: L('italy') },
        { ValueMember: "NL", DisplayMember: L('netherlands') },
        { ValueMember: "ES", DisplayMember: L('spain') },
        { ValueMember: "SE", DisplayMember: L('sweden') },
        { ValueMember: "GB", DisplayMember: L('unitedkingdom') }]),  
    selectedCountry: 0,
    countryPlaceholder: L('select_country')
});

原始堆栈跟踪

com.tns.NativeScriptException:  Calling js method onTouch failed

TypeError: Cannot set property 'disableNotifications' of undefined
File: "/data/data/org.nativescript.CareGiver/files/app/tns_modules/ui/gestures/gestures.js", line: 97, column: 40

StackTrace:   Frame: function:'Observable._setCore',
file:'/data/data/org.nativescript.CareGiver/files/app/tns_modules/data/observable/observable.js',
line: 136, column: 54     Frame: function:'Observable.set',
file:'/data/data/org.nativescript.CareGiver/files/app/tns_modules/data/observable/observable.js',
line: 129, column: 14     Frame: function:'Observable',
file:'/data/data/org.nativescript.CareGiver/files/app/tns_modules/data/observable/observable.js',
line: 50, column: 26  Frame: function:'Observable',
file:'/data/data/org.nativescript.CareGiver/files/app/tns_modules/data/observable/observable.js',
line: 47, column: 38  Frame: function:'MeasurementViewModel',
file:'/data/data/org.nativescript.CareGiver/files/app/models/measurement-view-model.js',
line: 16, column:
file:'/data/data/org.nativescript.CareGiver/files/app/models/measurement-view-model.js',
line: 16, column:

1 个答案:

答案 0 :(得分:1)

所以,在我的情况下,问题似乎是由于嵌套了Observables。通过删除嵌套的observable,不再抛出异常:

旧方式

var model = new Observable({
    measurements: new ObservableArray([]),
    recentMeasurement: {},
    notificationsEnabled: appSettings.getBoolean('notificationsEnabled', true),
    patientFirstName: "",
    patientLastName: "",
    units: "",
    hasMultipleConnections: true
});

新方法

var model = new Observable({
    measurements: [],
    recentMeasurement: {},
    notificationsEnabled: appSettings.getBoolean('notificationsEnabled', true),
    patientFirstName: "",
    patientLastName: "",
    units: "",
    hasMultipleConnections: true
});

这个改变似乎也导致了我安装和使用的一些插件的一些问题。你可以看到这提到的here on Github