【发布时间】:2015-07-08 15:17:35
【问题描述】:
全部,
我正在使用带有“#search”的路由器来启动从另一个视图中获取集合。
**Router code**
// DesktopRouter.js
// ----------------
define(["jquery", "backbone", "views/Page", "views/Form", "views/Results"],
function ($, Backbone, Page, Form, Results)
{
var DesktopRouter = Backbone.Router.extend({
initialize: function ()
{
// Tells Backbone to start watching for hashchange events
Backbone.history.start();
},
// All of your Backbone Routes (add more)
routes: {
// When there is no hash on the url, the home method is called
"": "index",
"search": "search"
},
index: function ()
{
console.log("Loading index");
// Instantiates a new view which will render the header text to the page
new Page();
new Form();
},
search: function ()
{
console.log("Loading search results view : " + selectedTrade);
var selectedTrade = $("#tradesField").val();
new Results(selectedTrade) //pass this value to the view which in turn passes to collection to pass in GET
}
...
表格
使用“#search”操作
<div class="col-md-3" id="form">
<p class="lead">Search for Tradesmen</p>
<div class="form-group">
<form action="#search">
<input id="tradesField" type="text" class="form-control">
<input id="searchTrades" type="submit" value="Search" class="btn btn-default form-control" />
</form>
</div>
</div>
第一次提交表单时,它工作正常。但是,我无法在第一次之后重新提交查询并触发该功能。我必须不断刷新页面并删除#search 标签。
我怎样才能让每个表单提交都能正常工作?
【问题讨论】:
标签: javascript backbone.js backbone-routing