简体   繁体   English

Javascript:将JSON字符串作为输入字符串(转义/逃逸)的值推送

[英]Javascript: Push JSON String as Value of an Input String (Escape/Unescape)

Following Situation (see plunker here: http://plnkr.co/edit/fOJ5zRvqCKvOC3olik8S?p=preview ): 以下情况(请参阅此处的punker: http ://plnkr.co/edit/fOJ5zRvqCKvOC3olik8S?p=preview):

在此处输入图片说明

<input ng-model="x" type="text">
<button ng-click="add(x)"> push input's value </button>

Text-Input has a JSON-String as value (I put it manually) Text-Input具有JSON-String作为值(我手动输入了它)

{ "i":3, "j":5 }

and I want to transfer its value and push it afterwards in Controller into an array. 我想转移它的值,然后将其在Controller中推入数组。 As you can see I've an escaped version of it in the array, what I want to avoide. 如您所见,我想避免使用数组中的转义版本。

How should my escape/unescape strategy look ? 我的逃生/逃生策略应如何看待? Where should I begin? 我应该从哪里开始?

使用以下内容:

$scope.a.push(JSON.parse(param));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM