使用angularjs中的alasql传递参数

时间:2016-12-26 10:42:20

标签: javascript angularjs alasql

我的角度js项目中的js将网格导出为ex​​cel, 继承我的代码:

 inventaire.exportMyDataVille = function(data) {

        var city='Safi';
        alasql('SELECT * INTO XLSX("data.xlsx",{headers:true}) FROM ? WHERE secteur='+city+' GROUP BY secteur,agence,serie', [inventaire.myDataSource]);
    };

我试图做的是在alasql中传递一个参数但是它给出了一个空的excel文件?请求中有什么错误

2 个答案:

答案 0 :(得分:1)

在SQL子句中应用字符串时,需要将字符串值包装在引号中。

根据您之前的选择,使用双引号,如下所示:

alasql('SELECT * INTO XLSX("data.xlsx",{headers:true}) FROM ? WHERE secteur="'+city+'" GROUP BY secteur,agence,serie', [inventaire.myDataSource]);

请注意从'+city+' "'+city+'"

的更改

答案 1 :(得分:1)

在这种情况下,@import url("https://fonts.googleapis.com/css?family=Open+Sans:300,400,600&display=swap"); .moveable { position: absolute; width: 250px; height: 200px; margin: 0 auto; background-color: transparent; top: 0; left: 0; } .my-new-box{ position: relative; width: 100%; height: 100%; background-color: #73a079; } .myTopLine, .myBottomLine{ background-color: #8b270a!important; display: flex!important; position: absolute!important; justify-content: space-between!important; align-items: flex-end!important; } .my-box { position: relative; top: 0; left: 0; width: 25px; height: 25px; /*flex: 1;*/ /*margin: 0 auto;*/ background-color: rgba(0,222,222,0.3); /*transform: translate3d(42px, -62px, -135px);*/ } .my-line{ position: relative; top: 0; left: 0; width: 100px; height: 150px; background-color: #3a3aa0; } .moveable-control-box { position: relative!important; background-color: #8b2c62 !important; } .label { position: fixed; top: 0; left: 0; padding: 5px; border-radius: 5px; background: #333; z-index: 3001; color: #fff; font-weight: bold; font-size: 12px; display: none; transform: translate(-100%, -100%); } .feature .container .left { position: relative; width: 300px; height: 205px; display: inline-block; vertical-align: top; z-index: 2000; margin-bottom: 20px; } .feature .container .right { position: relative; display: inline-block; vertical-align: top; flex: 1; } .feature .right .description { text-align: left; margin: 0px 0px 10px; } .feature .right .description strong { font-weight: 600; } .draggable, .resizable, .scalable, .rotatable, .origin, .warpable, .pinchable { position: absolute; left: 0; } .origin { transform-origin: 30% 50%; } pre { position: relative; border: 1px solid #ccc; box-sizing: border-box; padding: 10px; max-width: 500px; } code.hljs { padding: 0; } .tab { padding: 10px 12px; appearance: none; -webkit-appearance: none; background: transparent; border: 1px solid #ccc; box-shadow: none; font-weight: bold; margin: 0; cursor: pointer; outline: none; } .tab.selected { background: #333; color: #fff; border: 1px solid #333; } .panel { display: none; } .panel.selected { display: block; } .page.footer { font-weight: 400; } .page.footer a { text-decoration: underline; } .page.footer span:first-child:before { content: ""; } .page.footer span:before { content: "/"; } 函数需要格式 alasql

所以应该是:

( query, [[data], argument, argument, argumentN] )

alasql('... FROM ? WHERE secteur = ? ...', [inventaire.myDataSource, city]); 必须遵循格式 inventaire.myDataSource