1
我一直在尋找這個數小時,我不認爲我能夠看到解決方案。無法將數據從Sammy傳遞到淘汰賽模板
這是我router.js:
define('router', ['jquery', 'config', 'nav','store'], function ($, config, nav, store) {
var
concepTouch = Sammy('body', function() {
// This says to sammy to use the title plugin
this.use(Sammy.Title);
this.use(Sammy.Mustache);
// Sets the global title prefix
this.setTitle(config.title.prefix);
// So I can access sammy inside private methods
var sammy = this;
function establishRoutes() {
// Defines the main container for content then
var mainConainer = $(config.mainContentContainerId);
// Adds animation loading class to the main container
mainConainer.addClass(config.loadingAnimationCssClass);
// iterates through routes defined in config class then
_.forEach(config.appRoutes, function(obj, key) {
// defines each one as a route
sammy.get(obj.hashV, function(context) {
// Store the requested route as the last viewed route
store.save(config.stateKeys.lastView, context.path);
// Fetches its html template
context.render(obj.tmpltURL, { 'routeData': context.params })
// Appends that htmlo template to the main container and removes loading animation
.then(function(content) {
mainConainer.removeClass(config.loadingAnimationCssClass).html(content);
});
// Finally adds the route title to the prefix
this.title(obj.title);
});
// Overriding sammy's 404
sammy.notFound = function() {
// toast an error about the missing command
toastr.error(sammy.getLocation() + ' Does not exist yet!');
// Go to last visited anf if not
sammy.setLocation(
store.fetch(config.stateKeys.lastView) || config.getDefaultRoute()
);
};
});
}
// Calls for routes to be established
establishRoutes();
}),
// runs concep touch as a sammy App with the initial view of default route
init = function() {
// Try to get today's last visit and if not available then fallback on default
concepTouch.run(store.fetch(config.stateKeys.lastView) || config.getDefaultRoute());
// Make the correct nav item active and add Click handlers for navigation menu
nav.setStartupActiveClass(store.fetch(config.stateKeys.lastView) || sammy.getLocation())
.addActiveClassEventHandlers();
};
return {
init: init,
concepTouch: concepTouch
};
});
這時候我提交搜索表單得到這個模板我:
<div id="contacts" class="view animated fadeInLeft">
<h3>Search results for {{routeData}}</h3>
<ul data-bind="template: { name: 'searchresults-template', foreach: searchResults }"></ul>
</div>
<script type="text/html" id="searchresults-template">
<li data-bind="text: type"></li>
</script>
<script>
require(['searchresults'], function (searchresults) {
searchresults.get(to Some how Get routeData.term);
});
</script>
,我無法找到合適的方法,使鬍鬚通數據從router.js context.render(obj.tmpltURL, { 'routeData': context.params })
這一行的模板內部到{{routeData.term}}
。
{{routeData}} on its own returns `SAMMY.OBJECT: {"TERM": MY SEARCH TERM}`
我不能導航到我想從它使用的屬性。符號。而且即使工作不能被傳遞到JavaScript這是我真正需要的是
searchresults.init(); is waiting for this paramter `searchresults.init(routeData.term);`
或者,也許答案是找到一種方法來這裏訪問Sammy的背景?在sammy之外爲了得到參數?像Sammy.Application.context.params['term']
但是課程申請沒有這樣的方法,所以不知道!? :(
我該怎麼完全走錯路了呢?我怎麼能輕易通過查詢字符串PARAMS我的模板內的訪問對象,以便淘汰賽可以使用它。
你的幫助是極大的讚賞。
我希望Sammy.JS網站能夠在它的網站上推出的模板插件上寫出更多段落。 – XGreen