小编Dmi*_*hko的帖子

从中删除元素后,javascript数组的长度不会更改

我试图将一个数组值复制到另一个,但不打破与此数组关联的链接其他单词我不能只是将新数组分配给此值,这就是为什么我不能使用像slice()或concat()这样的方法.以下是执行该操作的函数的代码:

 self.updateBreadcrumbs = function (newBreadcrumbs) {
            var old_length = self.breadcrumbs.length;
            var new_length =newBreadcrumbs.length;
            var j = new_length > old_length ? new_length: old_length;

            for (var i = 0; i < j; i++) {
                if(old_length < i+1){
                    self.breadcrumbs.push(newBreadcrumbs[i]);
                    continue;
                }
                if(new_length < i+1){
                    delete self.breadcrumbs[i];
                    continue;
                }
                if (self.breadcrumbs[i].title !== newBreadcrumbs[i].title) {
                    self.breadcrumbs[i] = newBreadcrumbs[i];
                }

            }
        }
Run Code Online (Sandbox Code Playgroud)

我的问题是,当我从数组中删除某些内容时,数组的长度不会改变.

PS如果你知道任何更简单的方法,我对命题完全开放.

javascript arrays

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

在引导模块窗口中无法读取未定义输入文件的属性“ 0”

我正在尝试在Bootstrap模态中创建一个表单。它应该包含输入文件字段并预览选定的图像,因此我可以使用Jcrop裁剪图像。

所以这是我现在在做什么:

<script type="text/javascript">
    $('#new-menu').on('shown.bs.modal', function (event) {
        var modal = $(this);

        var src = modal.find(".modal-body .upload");
        var target = modal.find(".image");

        src.bind("change", function () {
            // fill fr with image data
            modal.find(".jcrop-holder").remove();
            readUrl(modal,target,src);
            initJcrop(target);
        });
    });

    function readUrl(modal,target,src){
        if (src.files && src.files[0]) {
            var reader = new FileReader();
            reader.onload = function (e) {
                target.attr('src', e.target.result);
            };
            reader.readAsDataURL(input.files[0]);
            initJcrop(target, modal);
        }
        else alert(src.files[0]);
    }
    }


    function showCoords(c) {
        $('#x').val(c.x);
        $('#y').val(c.y);
        $('#w').val(c.w);
        $('#h').val(c.h);
    }

    function initJcrop(img) {
        jcrop_api = $.Jcrop(img);

        jQuery(img).Jcrop({
            aspectRatio: …
Run Code Online (Sandbox Code Playgroud)

javascript jcrop twitter-bootstrap

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

如何为多个身份验证提供程序提供 Spring Security 的 java 配置

我将有关用户的信息存储在单独的表所有者、员工、用户中,我正在尝试在 Spring Security 中使用 java 配置。

我为每种用户类型创建了三个不同的身份验证提供程序,但只有用户提供程序被触发。我已经阅读了 spring 安全文档,唯一的方法似乎是创建具有多个从 WebSecurityConfigurerAdapter 扩展的嵌入式类的类,但我不想这样做,因为它需要大量重复代码,有没有另一种方式

我尝试使用简单的 userDetailService 在其中向数据库中的所有表发送请求,但仍然没有结果,只有一个查询正在执行而什么也没有,我得到的唯一响应是:

2016-02-09 23:06:25.976 DEBUG 8780 --- [nio-8080-exec-1] .saDefaultAuthenticationEventPublisher:未找到异常 org.springframework.security.authentication.InternalAuthenticationServiceException 的事件

2016-02-09 23:06:25.976 DEBUG 8780 --- [nio-8080-exec-1] osswawww.BasicAuthenticationFilter :身份验证请求失败:org.springframework.security.authentication.InternalAuthenticationServiceException:找不到实体进行查询;嵌套异常是 javax.persistence.NoResultException: No entity found for query

但我从不抛出任何异常!!最奇怪的是,我可以在调试器中看到在 em.createQuery(..).getSingleResult().. 之后执行如何迅速停止,仅此而已!没有return语句也没有什么异常,wtf!!

这是我当前配置的一部分:

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth
            .authenticationProvider(createAuthenticationProvider(employeeDetailService()))
            .authenticationProvider(createAuthenticationProvider(ownerDetailsService()))
            .authenticationProvider(createAuthenticationProvider(userDetailsService()));
}
 @Bean
    public OwnerDetailsService ownerDetailsService() {
        return new OwnerDetailsService();
    }

    @Bean
    public EmployeeDetailServiceImpl employeeDetailService() {
        return new EmployeeDetailServiceImpl();
    }

    @Bean
    public UserDetailsServiceImpl userDetailsService() {
        return new UserDetailsServiceImpl(); …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc spring-security

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

使用本机sql的插入方法上的Spring数据JpaException“无法提取ResultSet”

我在我的预订存储库中有一个简单的插入查询,但我无法正常工作;我尝试在 mysql 控制台中运行它并没有出现任何错误,我对使用本机查询标记的其他方法没有任何问题,我的存储库工作正常。

    @Query(value = "INSERT INTO user_reservation(movie_id, user_psid, is_activated) VALUES (?1,?2, false)", nativeQuery = true)
        void createSetMovie(int movieId, String userId);

    @Entity(name = "user_reservation")
    public class UserReservation {
        @Id
        @GeneratedValue
        private Integer id;

        @Column(name = "num_of_tickets", nullable = true)
        private int numberOfTickets;

        @Column(name = "is_activated")
        private boolean isActivated;
        @ManyToOne(optional = true)
        private Cinema cinema;
        @ManyToOne(optional = true)
        private Movie movie;
        @ManyToOne(optional = true)
        private MovieSession session;
        @ManyToOne(optional = true)
        private MessengerUser user;

        @Temporal(TemporalType.TIMESTAMP)
        private Date timestamp;

    ...
    gettters and setters …
Run Code Online (Sandbox Code Playgroud)

mysql spring hibernate jpa spring-data

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

在打包到jar后,Spring启动应用程序不提供静态资源

我有一个应用程序,通过ide或命令行启动时工作得很好:mvn spring-boot:run.但是当我将它打包到jar中时,我无法访问静态资源(未找到404).我不想在资源控制器中存储静态文件,所以每次我需要更改静态文件时都不必重新加载服务器.所以我在我的pom.xml中使用了这个插件:

              <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/target/classes/static</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/main/webapp</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Run Code Online (Sandbox Code Playgroud)

我可以看到文件正在两个目录"static"中复制.这是我的资源处理程序配置:

    @Configuration
    @EnableWebMvc
    public class WebMvcConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("/");
    }
Run Code Online (Sandbox Code Playgroud)

控制器RequestMappings工作正常,问题只与静态资源有关.

java spring spring-mvc maven spring-boot

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