是否有一种方法可以像angular js中使用$scope那样将值返回给twig ?

is there a way to return the value to twig as in angular js using $scope

本文关键字:scope twig 返回 js 一种 方法 angular 是否      更新时间:2023-09-26
function addCourse(x){
    $.post("../section/pages/tableContent.php", {data: x}, function(result) {
        //here
    });
};

在angular中我可以这样做

$http.post("../section/pages/tableContent.php", {data: x}).success(function (result) {
    $scope.students=result.records;
});

,因为我想循环生成的数组/对象

问题不是很清楚。但是看起来你想在php+twig中使用类似于angularjs的代码。

由于您使用的是ajax,一切都必须在客户端完成,但树枝是服务器端,所以它不会有帮助。但是你可以使用jquery本身。

function addCourse(x){
      $.post("../section/pages/tableContent.php", {data: x},                   
           function(result){
                $.each( result, function( i, val ) {
                     $("#id_of_your_ul").append("<li>"+val+"</li>");
                });
      });
};

如果你输入更多关于你正在尝试的内容的信息。我可以提供你需要做的事情