我有一个搜索表单,它将用户重定向到search/thetermusersearched,其中thetermusersearched是他输入的确切值。所有这些都是通过主干提供的导航功能实现的。
当我在英语中使用字符串(masa de calcat)时,这一切都很好,但是当我在输入(mas de călcat)中添加对话符时,我会触发两次路由函数。
我遇到的问题是火狐和Safari (后者在Mac和iOS中)
当我使用encodeURI和encodeURIComponent时,我尝试使用navigate,但没有成功。
HTML
<div id="view-goes-here">
<a href="#" data-string="masa de calcat">One alert</a>
<a href="#" data-string="masă de călcat">Two alerts</a>
</div>JS
var R = Backbone.Router.extend({
routes: {
'results/:query': 'results'
},
results: function(query) {
alert('Route triggered: ' + decodeURIComponent(query));
}
});
var myR = new R;
Backbone.history.start();
$(function(){
$('a').on('click', function(e){
e.preventDefault();
var href = $(this).data('string');
href = 'results/' + encodeURIComponent(href);
console.log(href);
myR.navigate(href, {trigger: true});
})
})见小提琴:http://jsfiddle.net/adyz/qcged76e/4/
对此有什么想法吗?
发布于 2016-10-08 18:21:21
你的小提琴上有两个链接,我得到了双重警告。我试着在编码后使用转义,这似乎是有效的:
href = 'results/' + escape(encodeURIComponent(href));https://stackoverflow.com/questions/39890991
复制相似问题