javascript - 使用 angularjs 将数据添加到 json-ld

标签 javascript json angularjs html web

我是 AngularJS 的初学者,我被困在我的一个项目中。我希望用户在表单中输入的数据转换为格式:<<"schema:data">> 并推送并显示在 json-ld 的 @graph 内。 这是我的 html 和 Angular 代码:

angular.module("watch", [])

.controller("ctrl", function($scope) {
    $scope.output = {
            "@context": {
            "schema": "http://schema.org/"
			},
           "@graph": [{
            "@id": "person",
			"@type": "schema:Person",
			}
			]
	
    }


    $scope.volatile = {};
    $scope.output["@graph"][0]["schema:givenName"] = "";
	
	
    $scope.$watch(function(scope) {
            return scope.volatile
	
        },
		function(newValue, oldValue) {
          $scope.output = newValue;
		     
			
		
        });
		
})
</script>
head>
    <title>
      reelyActive: Angular Test 
    </title>
	
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.min.js">
    </script>
    <script type="text/javascript" src="watch.js">
    </script>
	<link rel="stylesheet" href="style.css" />
  </head>
  <body ng-app="watch">
  <ul>
<li><a href="product.html">Product</a></li>
<li><a href="place.html">Place</a></li>

</ul><br/><br/>
    <div ng-controller="ctrl">
      <form>
        GivenName:  
        <input type="text" ng-model="volatile.givenName">
        <br/>
        FamilyName:	
        <input type="text" ng-model="volatile.familyName">
        <br/>
        Gender: 
        <input type="text" ng-model="volatile.gender">
        <br/>
        Nationality:
        <input type="text" ng-model="volatile.nationality">
        <br/>
        WorksFor: 
        <input type="text" ng-model="volatile.worksFor">
        <br/>
        JobTitle:
        <input type="text" ng-model="volatile.jobTitle">
        <br/>
        Url: 
        <input type="text" ng-model="volatile.url">
        <br/>
        Image:
        <input type="text" ng-model="volatile.image">
        <br/>
         </form>
         <h1>
           Your JSON
         </h1>
         <p>
           {{output}} 
         </p>
    </div>
	
	
	
	
  </body>
</html>

最佳答案

$scope.output['@graph'].push({
        "@id": "person",
        "@type": "schema:Person",
        });

关于javascript - 使用 angularjs 将数据添加到 json-ld,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30181497/

相关文章:

json - Kotlin - 数据类错误中的数组属性

c - 使用 json-c 解析深度嵌套的 JSON 键

android - AppInventor 麻烦了! (JSON 索引)

javascript - 在服务器中构建 html 并绑定(bind)到 ng-repeat

javascript - 未捕获的类型错误 : Cannot read property 'get' of null in map function

javascript - 将 npm 模块包装为 Ember Addons

javascript - Angular JS - 监听或绑定(bind) $http 请求

javascript - 解决 Firebase GetRecord 之前 View 加载不完整的问题

javascript - 将 jQuery 选择器用于 css,转义特殊字符

javascript - array.forEach 和 angular.forEach 哪个更高效?