durandal

Conditional routing in Durandal

与世无争的帅哥 提交于 2019-12-06 13:41:48
In my HotTowel based project, I'm using Durandal 1.1.1 for routing. I have a login route, which I want to activate if the user is not logged in. my route config is like: var routes = [ { url: 'login', moduleId: 'viewmodels/login', name: 'Login', visible: true, caption: 'Login' },{ url: 'moduledetail/:id', moduleId: 'viewmodels/moduledetail', name: 'ModuleDetail', visible: true, caption: 'ModuleDetail' } I want if user want to go #/moduledetail/1 and is not authenticated yet, the browser navigate to route #/login/moduledetail/1 so after successful login route back to the #/moduledetail/1 . A

Breeze Durandal Access shell viewmodel variable from view

房东的猫 提交于 2019-12-06 13:07:53
问题 I have a pretty simple thing I want to accomplish but I cannot figure out how or if it is even possible. I am using the Hot Towel template to start with. In the shell viewmodel I have a user observable. I would like to be able to reference that user observable from other pages on my site. For example from the home page. I tried a couple of things but it doenst appear as though I can access the shell from the composed view. I have a working solution at the moment that uses event pub/sub calls

prevent anchor tag from navigating to home page

落花浮王杯 提交于 2019-12-06 12:34:42
I have a regular anchor tag with href attribute set to "#". Normally, this prevents from any navigation but in durandal it navigates me to the home view. How can I stop it from navigating to that view? I can't change the html and stylings. It needs to be that anchor tag. But I can bind a click event to it. Is there any way to cancel navigation in anchor click event? regards Evan Larsen Bind a click event to it and call event.preventDefault() <a href="#" id="someAnchor">Example</a> $(function() { $('#someAnchor').click(function(event) { event.preventDefault(); }); }); This will prevent the

Breeze.js - getting error trying to use “any” operator - error: Unable to get value of the property 'isAnonymous': object is null or undefined

扶醉桌前 提交于 2019-12-06 10:29:32
I am trying to use the "any" operator in Breeze to query a many table and I am getting the following error - TypeError: Unable to get value of the property 'isAnonymous': object is null or undefined The only stackoverflow question I can find that seems related is this one, but there is no solution to the isAnonymous issue because the poster did not provide more code: breeze projection : error selecting non scalar navigation properties I am using Breeze 1.4.11 with Entity Framework 5 The query I am trying to run is var getEntities = function (entitiesObservable) { var whereClause = "";

Durandal constructor function but still want to remember data

谁说我不能喝 提交于 2019-12-06 08:55:47
Let's say I have the following durandal code: define(['durandal/app', 'plugins/http'], function (app) { var vm = function(){ var self = this; self.myData = ko.observableArray([]); } }; vm.activate = function() { this.myData([]); }; vm.deactivate = function(){ }; return vm; }; I know by returning a constructor function, every time the view model is activated, it will return a new instance. My question is: is there anyway that when I access, if there's myData() from previous access, then I don't want to set this.myData([]); but to use the previous myData() ? I know by returning a singleton

Durandal: Multiple Routes, One ViewModel/View

不打扰是莪最后的温柔 提交于 2019-12-06 07:32:37
I have 3 routes: items/one, items/two, and items/three and they're all pointing to 'items' vm/view. in the items.js activate function, I'm checking the url, and based on that, I'm changing a filter: function activate(r) { switch (r.routeInfo.url) { case 'items/one': vm.filterType(1); break; case 'items/two': vm.filterType(2); break; case 'items/three': vm.filterType(3); break; } return init(); //returns a promise } The items view has a menu with buttons for one, two, and three. Each button is linked to an action like this: function clickOne() { router.navigateTo('#/items/one'); } function

How to use the splat parameter in Durandal router?

百般思念 提交于 2019-12-06 05:29:09
问题 The article I am looking at is Durandal Router. Under mapAuto , it says we can pass splat parameter in the url #/customers/1 . and the activate function in the viewmodel will be able to retrieve the parameter array. I built a route here router.mapRoute('view/:id', moduleId, 'Customer Details', false); But how can I obtain the id in the activate function? There is no example on the doc page. Please help us out. Thank you. 回答1: Give your activate function a single parameter, perhaps named

How to create “full page dialog” with DurandalJS

心不动则不痛 提交于 2019-12-06 04:07:33
I'm trying to eliminate "css modal windows" (modal windows are not mobile device best friends) of a web client side application (SPA), built with DurandalJS version 2. I would like to convert the modal windows to full page dialogs. It would still be a dialog window but instead of superimpose the div over the current view, I would like to hide the current view (while keeping its state) and show the div containing the dialog (using the "entrance" transition if possible or a similar technique - to keep a consistent flow). I think I am close to a solution. The two options I'm trying at the moment

KO cannot find template with ID

ε祈祈猫儿з 提交于 2019-12-06 00:11:53
问题 I've used Knockout templates before, so I'm not sure why this isn't working for me. I tried two different styles of ko markup, neither work. <!-- more nesting levels --> <div class="cal-day-tps" data-bind="foreach: timePeriods"> <div class="cal-day-tp-cont"> <div data-bind="template: { name: 'tp-ed-templ', data: $data }"></div> //both of these methods fail <!-- ko template: { name: 'tp-ed-templ', data: $data } --> <!-- /ko --> </div> </div> <!-- /more nesting levels --> <script type="text

Durandal Widget with multiple views

允我心安 提交于 2019-12-05 23:04:38
I am working on a SPA using Durandal, and I have created a widget for displaying a particular page component. Following the Durandal Documentation , the widget is in app/widgets/my-widget and is composed of viewmodel.js and view.html . Now, I want to add a different view to the same widget - in effect, to have a "Basic" view and an "Advanced" view, with a flag in the ViewModel for which one will be used. I do not want to create two different widgets, because the ViewModel is exactly the same and I want to avoid unnecessary code duplication. I also do not want to put both versions of the view