小编pri*_*nce的帖子

如何在AngularJS中限制附件(文件上传)的大小?

我想要在AngularJS中上传带有加载图像的文件的最佳方法.同时我想将大小限制为10MB.

请给出实现这个目标的最佳方法?

angularjs angular-ui angularjs-directive angularjs-scope angularjs-ng-repeat

14
推荐指数
3
解决办法
4万
查看次数

如何使用underscore.js在Array中找到对象的索引?

我想使用underscore.js获取Array中给定值的索引.

这是我的情况

var array = [{'id': 1, 'name': 'xxx'},
             {'id': 2, 'name': 'yyy'},
             {'id': 3, 'name': 'zzz'}];

var searchValue = {'id': 1, 'name': 'xxx'};
Run Code Online (Sandbox Code Playgroud)

我使用了以下代码,

var index = _.indexOf(array, function(data) { 
                alert(data.toSource()); //For testing purpose 
                return data === searchValue; 
            });
Run Code Online (Sandbox Code Playgroud)

也试过这个

var index = _.indexOf(array, {id: searchValue.id});
Run Code Online (Sandbox Code Playgroud)

但它returns -1.因为它没有进入该功能.所以我没有得到那个警报信息.

我的代码出了什么问题.谁能帮我?

javascript javascript-framework underscore.js angularjs

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

如何运行量角器?

我对量角器很新.我在Windows命令行中运行它.

我按照本教程https://github.com/angular/protractor/blob/master/docs/getting-started.md

我成功地跑了 npm install -g protractor

我不知道如何运行它 node_modules/protractor/bin/install_selenium_standalone

如果我在命令行中直接运行它.我收到了这个错误'node_modules\protractor\bin\install_selenium_standalone' is not recognized as an internal or external command, operable program or batch file.

帮助我成功地运行它.以及这个命令./selenium/start

我在等待迅速的回应......

angularjs gruntjs angularjs-directive protractor

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

如何在InputStream中接收多个文件并相应地处理它?

我想收到从客户端上传的多个文件.我上传了多个文件并使用JAX-RS(Jersey)请求我的服务器端(Java ).

我有以下代码,

@POST
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public void upload(@Context UriInfo uriInfo,
            @FormDataParam("file") final InputStream is,
            @FormDataParam("file") final FormDataContentDisposition detail) {
FileOutputStream os = new FileOutputStream("Path/to/save/" + appropriatefileName);
    byte[] buffer = new byte[1024];
            int length;
            while ((length = is.read(buffer)) > 0) {
                os.write(buffer, 0, length);
            }
}
Run Code Online (Sandbox Code Playgroud)

如何在客户端上传的服务器端单独编写文件.

例如.我上传了诸如的文件My_File.txt, My_File.PNG, My_File.doc.我需要My_File.txt, My_File.PNG, My_File.doc在服务器端编写与上面相同的内容.

我怎样才能做到这一点?

java inputstream file jax-rs jersey

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

如何禁用从Angular JS下拉列表中选择特定选项?

我想禁用AngularJS下拉列表中的特定选项.

它应该在下拉列表中列出,但不应该允许它被选中.所以我需要禁用它.

MyFile.tpl.html

<select class="form-control" ng-model="selectedFruits" 
        ng-options="fruit as fruit.name for fruit in fruits">
</select>
Run Code Online (Sandbox Code Playgroud)

MyController.js

$scope.fruits = [{'name': 'apple', 'price': 100},{'name': 'guava', 'price': 30},
                 {'name': 'orange', 'price': 60},{'name': 'mango', 'price': 50},
                 {'name': 'banana', 'price': 45},{'name': 'cherry', 'price': 120}];
Run Code Online (Sandbox Code Playgroud)

这里所有的水果名称都应该在下拉列表中列出,但芒果樱桃应该被禁用,不应该让用户选择它.

可能吗?如果可能,请告诉我解决方案.

javascript html-select angularjs

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

如何使用JAX-RS从Java服务器端返回Zip文件?

我想使用JAX-RS从我的服务器端java返回一个压缩文件到客户端.

我尝试了以下代码,

@GET
public Response get() throws Exception {

    final String filePath = "C:/MyFolder/My_File.zip";

    final File file = new File(filePath);
    final ZipOutputStream zop = new ZipOutputStream(new FileOutputStream(file);

    ResponseBuilder response = Response.ok(zop);
    response.header("Content-Type", "application/zip");
    response.header("Content-Disposition", "inline; filename=" + file.getName());
    return response.build();
}
Run Code Online (Sandbox Code Playgroud)

但我得到的例外情况如下,

SEVERE: A message body writer for Java class java.util.zip.ZipOutputStream, and Java type class java.util.zip.ZipOutputStream, and MIME media type application/zip was not found
SEVERE: The registered message body writers compatible with the MIME media type are:
*/* ->
  com.sun.jersey.core.impl.provider.entity.FormProvider …
Run Code Online (Sandbox Code Playgroud)

java outputstream jax-rs jersey filestream

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

使用的目的是什么!! 在JavaScript?

我想知道!!在JS 中使用的目的.

例如:

this.enabled = function (value) {
   if (arguments.length) {
    enabled = !!value;
    }
}
Run Code Online (Sandbox Code Playgroud)

javascript

0
推荐指数
1
解决办法
1762
查看次数

如何使用underscore.js在javascript数组中找到给定值?

我想知道javascript数组中是否存在给定值.

这是我的情况,

var array = [{'id': 1, 'name': 'xxx'},
         {'id': 2, 'name': 'yyy'},
         {'id': 3, 'name': 'zzz'}];

 var searchValue = {'id': 1, 'name': 'xxx'};
Run Code Online (Sandbox Code Playgroud)

我试过以下,

var exists = _.where(array, {name: 'xxx'});
Run Code Online (Sandbox Code Playgroud)

它返回obj {'id': 1, 'name': 'xxx'}.它按预期工作.

在这里,我需要检查exists.length > 0是否存在

但是有没有其他功能得到相同.

因为如果函数返回,true如果存在,false如果不存在,那就更好了.

javascript javascript-framework underscore.js angularjs

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