簡體   English   中英

如何使用angularJS更改對象的屬性

[英]How to change the property of object using angularJS

我正在使用劍道網格。 在“ options.models”下,我有3個列表,其中一個是日期時間。 我想訪問該屬性並在日期上執行一些解析。 由於我是編碼新手,所以我對此一無所知。 任何幫助將不勝感激。

 parameterMap: function(options, operation) {
    if (operation !== "read" && options.models) {
        angular.forEach(options.models, function(value) {
            //****???****//
        })
        return options;
    }
 }

所以現在我的代碼看起來像這樣。 感謝@Sachila為我工作。

parameterMap: function (options, operation) {
                    if (operation !== "read" && options.models) {
                        angular.forEach(options.models, function (value) {
                            value.Mfg_Dt = kendo.toString(value.Mfg_Dt, "s");
                        })
                        return options;
                    }
                }

假設您要更改“ Exp_Dt”,然后嘗試執行此操作

angular.forEach($scope.arr, function(value) {
    value.Exp_Dt = new Date(); // assign whatever date 
})

 angular.module("app",[]) .controller("ctrl",function($scope){ $scope.arr = [{ Exp_Dt: "Sun Feb 26 2017 16: 44: 31 GMT + 0530(India Standard Time)", Id: 0, Mfg_Dt: "Sun Feb 26 2017 16: 44: 31 GMT + 0530(India Standard Time)", Product_Name: "P3", Product_Type: "T3", Strip_No: 5, Strip_Unit: 6, Total: 0 }]; angular.forEach($scope.arr, function(value) { value.Exp_Dt = new Date(); // assign whatever date }) console.log($scope.arr) }) 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="app" ng-controller="ctrl"> </div> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM