繁体   English   中英

如何使用angular.js将javascript数组变量值传递给html

[英]How to pass javascript array variable values to html using angular.js

我是angular.js的新手

我想通过填充javascript数组变量中的值来创建表。 我在这个变量中创建并输入了值

        var result=[];    

        //some loop. Just demonstrating that there are multiple values of id and text
        result.push(
            {
                "id":obj["id"],                
                "text":obj["text"],
            }
        );

我希望html中的结果变量中的每个id和text都有一个新行

<table>
<tr><td>id</td><td>text</td></tr>
<table>

使用angular.js的方法是什么。

弄清楚了。 如果有人需要它,把它放在这里。

Javascript代码:

function controller($scope, $http) {

    $scope.results=[];
    $http.get(url).success(function (data) {

        $.each(data, function () {
            var obj = data;
            console.log(obj);
            $scope.results.push(
                {
                    "id": obj["obj_id"],                    
                    "text": obj["text"]
                }
            );


        });
    });


}

HTML代码

<div  ng-controller="controller">
    <table ng-repeat="result in results">
    <tr><td>{{result.id}}</td><td>{{result.text}}</td></tr>
    <table>
</div>

暂无
暂无

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

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