admin管理员组文章数量:1291198
This is got to be simple so here's the deal;
I place the following ARRAY of objects (JSON) into local storage and it appears like this:
[{"id": 150, "label": "Animal Cookies (Phat Panda)"}, {"id": 110, "label": "Blue Dream (Pioneer)"}, {"id": 30, "label": "Candyland"}, {"id": 130, "label": "Dragon OG (Avitas)"}, {"id": 20, "label": "Golden Pineapple Family"}, {"id": 140, "label": "Golden Ticket (Liberty Reach)"}, {"id": 120, "label": "GSC: Thin Mint (Phat Panda)"}, {"id": 40, "label": "Jack Herer Master Blend"}, {"id": 80, "label": "Owyn's White Widow Blend Master"}, {"id": 50, "label": "P91 San Diego Family"}, {"id": 60, "label": "Phat Panda"}, {"id": 100, "label": "Space Queen Family Sativa"}, {"id": 10, "label": "Trash"}, {"id": 70, "label": "Urkel"}, {"id": 90, "label": "White Widow"}]
Yes, these are Cannabis strains and I'm building a software for Cannabis growers.
PROBLEM:
When I retrieve it like so:
/**
* Angular Dropdown Multi-select
* - <<<< EXAMPLE HERE!
* For STRAINS to select what will be in the room selected
*
*/
$scope.plantWizModel = [];
$scope.plantWizData = [];
//Get the REFORMATTED data from LOCALSTORAGE
//$scope.plantWizData = storageLocalService.getItemJSON("strainsmini");
$scope.plantWizData = [{"id": 150, "label": "Animal Cookies (Phat Panda)"}, {"id": 110, "label": "Blue Dream (Pioneer)"}, {"id": 30, "label": "Candyland"}, {"id": 130, "label": "Dragon OG (Avitas)"}, {"id": 20, "label": "Golden Pineapple Family"}, {"id": 140, "label": "Golden Ticket (Liberty Reach)"}, {"id": 120, "label": "GSC: Thin Mint (Phat Panda)"}, {"id": 40, "label": "Jack Herer Master Blend"}, {"id": 80, "label": "Owyn's White Widow Blend Master"}, {"id": 50, "label": "P91 San Diego Family"}, {"id": 60, "label": "Phat Panda"}, {"id": 100, "label": "Space Queen Family Sativa"}, {"id": 10, "label": "Trash"}, {"id": 70, "label": "Urkel"}, {"id": 90, "label": "White Widow"}];
console.log("PLANT WIZ DATA: ", $scope.plantWizData);
$scope.plantWizSettings = {
checkBoxes: true
};
$scope.plantWizCustomTexts = {
buttonDefaultText: 'Select up to 4 Strains',
selectionLimit: 4
};
What I get is THIS: PERFECTION...
BUT, when I change the code from "HARD CODING" the $scope.plantWizData like so:
$scope.plantWizData = storageLocalService.getItemJSON("strainsmini");
The error I get is this:
angular.js:12332 Error: [ngRepeat:dupes] Duplicates in a repeater are not
allowed. Use 'track by' expression to specify unique keys. Repeater: option
in options, Duplicate key: string:", Duplicate value: "
.4.2/ngRepeat/dupes?p0=option%20in%20options&p1=string%3A%22&p2=%22
at angular.js:68
at ngRepeatAction (angular.js:27144)
at Object.$watchCollectionAction [as fn] (angular.js:15550)
at Scope.$digest (angular.js:15685)
at Scope.$apply (angular.js:15953)
at done (angular.js:10366)
at pleteRequest (angular.js:10538)
at XMLHttpRequest.requestLoaded (angular.js:10479)
Therefore, this is the result:
What's apparently occuring is that when I get the data from LOCAL STORAGE, "" appear LEADING and TRAILING on $scope.plantWizData = []; like so:
$scope.plantWizData = >>>> "[{"id": 150, "label": "Animal Cookies (Phat Panda)"}, {"id": 110, "label": "Blue Dream (Pioneer)"}, {"id": 30, "label": "Candyland"}, {"id": 130, "label": "Dragon OG (Avitas)"}, {"id": 20, "label": "Golden Pineapple Family"}, {"id": 140, "label": "Golden Ticket (Liberty Reach)"}, {"id": 120, "label": "GSC: Thin Mint (Phat Panda)"}, {"id": 40, "label": "Jack Herer Master Blend"}, {"id": 80, "label": "Owyn's White Widow Blend Master"}, {"id": 50, "label": "P91 San Diego Family"}, {"id": 60, "label": "Phat Panda"}, {"id": 100, "label": "Space Queen Family Sativa"}, {"id": 10, "label": "Trash"}, {"id": 70, "label": "Urkel"}, {"id": 90, "label": "White Widow"}]" <<<<;
So, how do I get rid of them because I need to keep this solution DYNAMIC and not STATIC?
Thank you.
This is got to be simple so here's the deal;
I place the following ARRAY of objects (JSON) into local storage and it appears like this:
[{"id": 150, "label": "Animal Cookies (Phat Panda)"}, {"id": 110, "label": "Blue Dream (Pioneer)"}, {"id": 30, "label": "Candyland"}, {"id": 130, "label": "Dragon OG (Avitas)"}, {"id": 20, "label": "Golden Pineapple Family"}, {"id": 140, "label": "Golden Ticket (Liberty Reach)"}, {"id": 120, "label": "GSC: Thin Mint (Phat Panda)"}, {"id": 40, "label": "Jack Herer Master Blend"}, {"id": 80, "label": "Owyn's White Widow Blend Master"}, {"id": 50, "label": "P91 San Diego Family"}, {"id": 60, "label": "Phat Panda"}, {"id": 100, "label": "Space Queen Family Sativa"}, {"id": 10, "label": "Trash"}, {"id": 70, "label": "Urkel"}, {"id": 90, "label": "White Widow"}]
Yes, these are Cannabis strains and I'm building a software for Cannabis growers.
PROBLEM:
When I retrieve it like so:
/**
* Angular Dropdown Multi-select
* http://dotansimha.github.io/angularjs-dropdown-multiselect/docs/#/main - <<<< EXAMPLE HERE!
* For STRAINS to select what will be in the room selected
*
*/
$scope.plantWizModel = [];
$scope.plantWizData = [];
//Get the REFORMATTED data from LOCALSTORAGE
//$scope.plantWizData = storageLocalService.getItemJSON("strainsmini");
$scope.plantWizData = [{"id": 150, "label": "Animal Cookies (Phat Panda)"}, {"id": 110, "label": "Blue Dream (Pioneer)"}, {"id": 30, "label": "Candyland"}, {"id": 130, "label": "Dragon OG (Avitas)"}, {"id": 20, "label": "Golden Pineapple Family"}, {"id": 140, "label": "Golden Ticket (Liberty Reach)"}, {"id": 120, "label": "GSC: Thin Mint (Phat Panda)"}, {"id": 40, "label": "Jack Herer Master Blend"}, {"id": 80, "label": "Owyn's White Widow Blend Master"}, {"id": 50, "label": "P91 San Diego Family"}, {"id": 60, "label": "Phat Panda"}, {"id": 100, "label": "Space Queen Family Sativa"}, {"id": 10, "label": "Trash"}, {"id": 70, "label": "Urkel"}, {"id": 90, "label": "White Widow"}];
console.log("PLANT WIZ DATA: ", $scope.plantWizData);
$scope.plantWizSettings = {
checkBoxes: true
};
$scope.plantWizCustomTexts = {
buttonDefaultText: 'Select up to 4 Strains',
selectionLimit: 4
};
What I get is THIS: PERFECTION...
BUT, when I change the code from "HARD CODING" the $scope.plantWizData like so:
$scope.plantWizData = storageLocalService.getItemJSON("strainsmini");
The error I get is this:
angular.js:12332 Error: [ngRepeat:dupes] Duplicates in a repeater are not
allowed. Use 'track by' expression to specify unique keys. Repeater: option
in options, Duplicate key: string:", Duplicate value: "
http://errors.angularjs/1.4.2/ngRepeat/dupes?p0=option%20in%20options&p1=string%3A%22&p2=%22
at angular.js:68
at ngRepeatAction (angular.js:27144)
at Object.$watchCollectionAction [as fn] (angular.js:15550)
at Scope.$digest (angular.js:15685)
at Scope.$apply (angular.js:15953)
at done (angular.js:10366)
at pleteRequest (angular.js:10538)
at XMLHttpRequest.requestLoaded (angular.js:10479)
Therefore, this is the result:
What's apparently occuring is that when I get the data from LOCAL STORAGE, "" appear LEADING and TRAILING on $scope.plantWizData = []; like so:
$scope.plantWizData = >>>> "[{"id": 150, "label": "Animal Cookies (Phat Panda)"}, {"id": 110, "label": "Blue Dream (Pioneer)"}, {"id": 30, "label": "Candyland"}, {"id": 130, "label": "Dragon OG (Avitas)"}, {"id": 20, "label": "Golden Pineapple Family"}, {"id": 140, "label": "Golden Ticket (Liberty Reach)"}, {"id": 120, "label": "GSC: Thin Mint (Phat Panda)"}, {"id": 40, "label": "Jack Herer Master Blend"}, {"id": 80, "label": "Owyn's White Widow Blend Master"}, {"id": 50, "label": "P91 San Diego Family"}, {"id": 60, "label": "Phat Panda"}, {"id": 100, "label": "Space Queen Family Sativa"}, {"id": 10, "label": "Trash"}, {"id": 70, "label": "Urkel"}, {"id": 90, "label": "White Widow"}]" <<<<;
So, how do I get rid of them because I need to keep this solution DYNAMIC and not STATIC?
Thank you.
Share Improve this question asked Oct 21, 2017 at 16:18 Peter The Angular DudePeter The Angular Dude 1,1887 gold badges28 silver badges61 bronze badges 3- Why is use of angularjs necessary? – guest271314 Commented Oct 21, 2017 at 16:21
-
1
Probably because you haven't parsed the json in
storageLocalService.getItemJSON
. Show that code – charlietfl Commented Oct 21, 2017 at 16:22 -
Can also save yourself setting and getting by using
ngStorage
module – charlietfl Commented Oct 21, 2017 at 16:23
2 Answers
Reset to default 10You can use template literal to create valid JSON
without leading or trailing double quotation marks
let json = `[{"id": 150, ..}]`;
localStorage.setItem("json", json);
let o = JSON.parse(localStorage.getItem("json"));
Using JSON.parse
removes double quotes.
本文标签:
版权声明:本文标题:javascript - How to remove leading and trailing double-quotes coming from local storage using angular or JQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741505488a2382294.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论