Knockout.js重复脚本

时间:2016-08-07 23:17:01

标签: javascript jquery knockout.js

当我把两个ko.js放在一起时,其中一个被第一个黯然失色,我的意思是第二个停止工作,只是第一个工作,我怎样才能将它们合并在一起并让它们正常工作而没有任何问题。他们分开工作很好而不是在一起为什么会这样?



projects#index
                   project_tasks GET      /projects/:project_id/tasks(.:format)          tasks#index
                                 POST     /projects/:project_id/tasks(.:format)          tasks#create
                new_project_task GET      /projects/:project_id/tasks/new(.:format)      tasks#new
               edit_project_task GET      /projects/:project_id/tasks/:id/edit(.:format) tasks#edit
                    project_task GET      /projects/:project_id/tasks/:id(.:format)      tasks#show
                                 PATCH    /projects/:project_id/tasks/:id(.:format)      tasks#update
                                 PUT      /projects/:project_id/tasks/:id(.:format)      tasks#update
                                 DELETE   /projects/:project_id/tasks/:id(.:format)      tasks#destroy
                        projects GET      /projects(.:format)                            projects#index
                                 POST     /projects(.:format)                            projects#create
                     new_project GET      /projects/new(.:format)                        projects#new
                    edit_project GET      /projects/:id/edit(.:format)                   projects#edit
                         project GET      /projects/:id(.:format)                        projects#show
                                 PATCH    /projects/:id(.:format)                        projects#update
                                 PUT      /projects/:id(.:format)                        projects#update
                                 DELETE   /projects/:id(.:format)                        projects#destroy




1 个答案:

答案 0 :(得分:0)

正如@Jeroen所述,您应该将代码缩减为minimal, complete, and verifiable example

然而,knockout将它绑定到整个DOM。不止一次在整个DOM上调用applyBindings是没有意义的。如果页面的不同部分有不同的视图模型,pass the DOM element您希望在applyBindings期间绑定每个视图模型:

 ko.applyBindings(new vm(), document.getElementById('someElementId'))