TypeError:无法分配给只读属性&#39;已完成&#39; #<object>

时间:2017-02-06 16:03:35

标签: javascript android angularjs cordova ionic-framework

我有一个用Cordova / Ionic制作的应用程序。我正在使用AngularJS。我有以下问题。

TypeError: Cannot assign to read only property 'done' of #<Object>
at fn.assign (eval at <anonymous> (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:1:0), <anonymous>:4:390)
at $$writeModelToScope (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:38359:5)
at writeToModelIfNeeded (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:38353:14)
at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:38347:9
at validationDone (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:38275:9)
at processAsyncValidators (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:38258:9)
at $$runValidators (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:38202:5)
at $$parseAndValidate (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:38340:10)
at $commitViewValue (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:38308:10)
at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:38441:14 

TypeError: Cannot assign to read only property 'criticality' of #<Object>
at fn.assign (eval at <anonymous> (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:26457:15), <anonymous>:4:482)
at $$writeModelToScope (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:38359:5)
at writeToModelIfNeeded (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:38353:14)
at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:38347:9
at validationDone (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:38275:9)
at processAsyncValidators (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:38258:9)
at $$runValidators (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:38202:5)
at $$parseAndValidate (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:38340:10)
at $commitViewValue (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:38308:10)
at $$debounceViewValueCommit (file:///android_asset/www/lib/ionic/js/ionic.bundle.js:38438:12) 

在我对该主题进行了一些研究后,我意识到当您在javascript文件(click here for the documentation explaining this)中使用'USE STRICT'时会出现此类错误。问题是我从未这样做过。我没有使用'USE STRICT'。现在,这是更奇怪的事情。这个问题只发生在配备Android 4.4.2的三星GT-N5110平板电脑上。在安装了最新更新的Samsung Galaxy S7上不会发生这种情况。如果我使用命令ionic serve在我的计算机上为appplication提供午餐,那么它也不会发生。它按预期完美地工作。它只发生在三星平板电脑上。我尝试了很多东西,但我找不到任何解决办法。它在平板电脑上运行非常重要,因为这些是我们将用于工作的平板电脑。

它发生在多个变量上,但我会提供变量代码&#39; done&#39;如第一条错误消息所示。

我点击ion-checkbox以更改&#39;已完成&#39;

的值的视图
<div class="card" ng-repeat="item in etapes" ng-click="itemDetails(item.id)">
    <div class="item item-text-wrap">
    <p><b>{{'components.inspection.etape.card.title'  | translate}}</b> {{item.name}}</p>
    <p><b>{{'components.inspection.etape.card.duration'  | translate}}</b> {{item.duration}} minutes</p>
    <p><b>{{'components.inspection.etape.card.description'  | translate}}</b></p>
    <p ng-bind-html="item.description"></p>
    <ion-checkbox ng-disabled="completed" class="item item-input" ng-model="item.done" ng-true-value="1" ng-false-value="0" ng-click="$event.stopPropagation()" ng-change="itemDone(item)" style="width: 100%; border: 0">{{'components.inspection.etape.card.completed'  | translate}}</ion-checkbox>
    </div>
</div>

JS文件(方法是$ scope.itemDone)

angular.module('app.controllers')
.controller('etapeController', ['$state', '$stateParams', '$scope', '$translate', 'Inspection', 'InspectionItem', 'ItemPhoto', '$ionicHistory', 'Camera', '$ionicPopup', '$q', 'InspectionTree', 'InspectionEtape', 'Loading', 'ExportInspection', 'EtapeComment', 'CommentPhoto',
    function ($state, $stateParams, $scope, $translate, Inspection, InspectionItem, ItemPhoto, $ionicHistory, Camera, $ionicPopup, $q, InspectionTree, InspectionEtape, Loading, ExportInspection, EtapeComment, CommentPhoto) {
        var inspectionId = $stateParams.inspectionId;
        var itemId = $stateParams.itemId;
        $scope.etapes = [];
        Loading.show();

        var loadingPromises = [];
        loadingPromises.push(
            InspectionEtape.getByInspectionId(inspectionId).then(function (f) {
                for (var i = 0; i < f.length; i++) {
                    var item = {}
                    item = f[i];
                    $scope.etapes.push(item);
                }
            }));
        loadingPromises.push(
            Inspection.get(inspectionId).then(function (res) {
                $scope.completed = res.status;
            })
        );
        $q.all(loadingPromises).then(function () {
            Loading.hide();
        })


        $scope.itemDetails = function (id) {
            $state.go("app.inspection_etape_comment", { inspectionId: inspectionId, etapeId: id });
        }

        $scope.itemDone = function (etape) {
            if(!$scope.completed)
                InspectionEtape.updateChecked(etape.id, etape.done == true ? 1 : 0);
        }

        $scope.tryFinishInspection = function () {
            $state.go("app.inspection_summary_edit", {inspectionId: inspectionId});
        }
    }]);

在花了很多时间试图找出问题之后,我决定向社区寻求帮助。我非常感激!先感谢您。如果您需要更多说明,请告诉我们!

1 个答案:

答案 0 :(得分:1)

好吧,我最终找到了解决方案!由于它不适用于旧设备,但它适用于新设备,我考虑在系统webview上安装webview。所以我所做的就是安装crosswalk webview(cordova plugin add cordova-plugin-crosswalk-webview)并解决了我的问题!