小编Gui*_*rmo的帖子

AngularJS - 基于json构建动态表

鉴于这样的json:

{
   "name": "john"
   "colours": [{"id": 1, "name": "green"},{"id": 2, "name": "blue"}]
}
Run Code Online (Sandbox Code Playgroud)

和两个常规的html输入:

<input type="text" name="name" />
<input type="text" name="color" />
<input type="submit" value="submit" />
Run Code Online (Sandbox Code Playgroud)

我需要构建一个包含所有可能变体的表格,例如:

John green
John blue
Run Code Online (Sandbox Code Playgroud)

这意味着如果用户继续通过输入添加值,则新行将显示构建新变体,例如:

我还需要有可用的id来处理它,我需要当我使用输入添加新值时:例如:"Peter""Black",我需要动态自动填充id(颜色id),就像自动增量一样mysql,导致这样的事情:

{
  "colours": […...{"id": 3, "name": "black"}]
}
Run Code Online (Sandbox Code Playgroud)

那可能吗?使用棱角镜可以选择哪种方式?我仍在以jQuery的方式思考,我想以有角度的方式做到这一点.

我看了一下hg-​​repeat,然后使用它,但是我没有弄清楚如何提供预期的结果,我想到的唯一的事情是使用嵌套的ng-repeats,但它没有用.

非常感谢,提前,

吉列尔莫

javascript angularjs

27
推荐指数
2
解决办法
13万
查看次数

AngularJS - 表单自定义验证 - 检查至少一个输入是否为空

给出一个像这样的简单html表单:

<form name="myForm" action="#sent" method="post" ng-app>
   <input name="userPreference1" type="text" ng-model="shipment.userPreference" />
   <input name="userPreference1" type="text" ng-model="shipment.userPreference" />
   <input name="userPreference1" type="text" ng-model="shipment.userPreference" />
... submit input and all the other code...
</form>
Run Code Online (Sandbox Code Playgroud)

如果至少有一个输入是空的,我需要你的帮助才能知道如何检查验证时间.所需的验证如下.用户必须至少完成一个偏好.

使用jQuery:

if ( $("input").val() == "" ) {
Run Code Online (Sandbox Code Playgroud)

工作正常,但想知道如何使用角度做同样的事情.

非常感谢,提前,

吉列尔莫

html javascript validation angularjs

13
推荐指数
1
解决办法
3万
查看次数

如何沿给定路径拖动形状

我有这个简单的虚拟文件,我正在用它做一些测试.预期的结果是沿路径拖动红色圆圈.问题是我无法弄清楚如何关联两个形状.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />    
    <script src="raphael-min.js"></script>    
</head>
<body>    
<script type="text/javascript">    
// Creates canvas 320 × 200 at 10, 50
var r = Raphael(10, 50, 320, 200);

var p = r.path("M100,100c0,50 100-50 100,0c0,50 -100-50 -100,0z").attr({stroke: "#ddd"}),
    e = r.ellipse(104, 100, 4, 4).attr({stroke: "none", fill: "#f00"}),


/*var c = r.circle(100, 100, 50).attr({
    fill: "hsb(.8, 1, 1)",
    stroke: "none",
    opacity: .5
});*/


var start = function () {
    // storing original coordinates
    this.ox = this.attr("cx");
    this.oy = this.attr("cy"); …
Run Code Online (Sandbox Code Playgroud)

javascript graphics svg raphael

12
推荐指数
2
解决办法
5852
查看次数

AngularJS - 同时检测未定义的null或空值的最佳方法是什么?

有时我需要同时检查三个条件的值,null,undefined或"".由于我还没有找到任何方法来做到这一点,我编写了自己的编码方法.

$scope.isNullOrEmptyOrUndefined = function (value) {
    if (value === "" || value === null || typeof value === "undefined") {
        return true;
    }
}
Run Code Online (Sandbox Code Playgroud)

只是想知道是否有更好的方法来完成同样的事情.

非常感谢,提前,

吉列尔莫

angularjs

6
推荐指数
2
解决办法
6万
查看次数

Babel和typeahead的问题

在node.js项目中使用babel时,我正在尝试将所有文​​件捆绑到一个已编译和缩小的js文件中.

我正在使用gulp-babel 6.1.2运行babel,我已经安装了ES-2015预设(6.13.2).

我正在使用我的文件构建一个包,并且输入0.11.1,问题是当运行gulp任务并通过babel管道时,输入的功能不起作用(Uncaught TypeError:无法设置未定义的属性'Bloodhound').如果我再次运行任务,从管道中删除babel命令,一切正常.

我知道我可以构建两个单独的包,一个用于我的文件,另一个用于外部文件,但我想知道为什么它失败了.

我的任务:

gulp.task('bundleCheckoutDesktopJs', function () {
var js = ['./src/js/project/external/*', './src/js/project/common/*', './src/js/project/*'];

return gulp.src(js)
    .pipe(babel())
    .pipe(concat('project.min.js'))
    .pipe(uglify())
    .pipe(gulp.dest('statics/js/'));
});
Run Code Online (Sandbox Code Playgroud)

调查一段时间后我获得的结果(typeahead.js):

(function(root, factory) {
   if (typeof define === "function" && define.amd) {
      define("bloodhound", [ "jquery" ], function(a0) {
          return root["Bloodhound"] = factory(a0);
      });
   } else if (typeof exports === "object") {
      module.exports = factory(require("jquery"));
   } else {
     // Root seems to be undefined here....
     root["Bloodhound"] = factory(jQuery);

   }
})
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激,提前感谢.

javascript node.js typeahead.js gulp gulp-babel

5
推荐指数
1
解决办法
198
查看次数

单元测试/测试文件中是否存在函数

我想知道是否有一种方法使用 mocha 和 chai 来测试代码是否存在整段代码,例如这样的函数。

myfunction(arg1) {
    ......
}
Run Code Online (Sandbox Code Playgroud)

如果代码存在,则测试应返回 true。

PD:我知道测试整段代码可能看起来是一件令人讨厌的事情,但有时在进行培训时,学生会编写很多代码,如果某些东西不起作用,我们应该检查他们已完成的整套步骤,为了避免这种情况,我想编写一个测试来查找某些代码片段。我已经编写了其他测试来检查参数是否存在、数组元素长度等。

提前致谢。

javascript unit-testing mocha.js node.js chai

4
推荐指数
1
解决办法
1731
查看次数

在所有承诺得到解决后执行承诺

我编写了一些迭代目录的代码,选择所有的jpg文件,重命名它们,创建thumb文件夹并将它们放在该文件夹中.我还编写了一个函数,每个图像生成一个html块,并且在forEach循环结束时应该将所有输出写入文件.

// Read the directory
fs.readdir(dir, function (err, files) {

// Return the error if something went wrong
if (err) {
    console.log("Something went wrong");
}

//Make thumbs dir
fs.mkdirSync(thumbsFolder);

// For every file in the list
files.forEach(function (file) {
    var extension = path.extname(file);

    if (extension === ".jpg") {

        //Rename images
        var renameTask = renameImages(file, newFileName, extension);

        //Generating thumbs
        renameTask.then(function (newFileName) {
            generateThumbs(dir, newFileName, thumbsFolder)
            console.log("Promise resolved! Generating thumb for: " + newFileName);
            galleryHtml += generateThumbsGallery(newFileName, articleTitle);

        }, function (err) { …
Run Code Online (Sandbox Code Playgroud)

javascript node.js promise ecmascript-6 es6-promise

3
推荐指数
1
解决办法
2802
查看次数

管理每周时间表的数据库模式

我正在写这篇文章,因为我想知道是否有人可以帮我弄清楚一个简单的时间表应用程序的最佳数据库架构.

我无法弄清楚如何绘制表格来帮助我代表一年中的几周,所有用户都将在工作周记录他们的工作.

干杯,非常感谢您的帮助!:)

吉列尔莫

php sql database database-design

2
推荐指数
1
解决办法
6884
查看次数