Conditional rendering on load with AMP-HTML - rendering

I have a JSON file and I'd like to render elements based on the value of a property in JSON file. Let's think the JSON is something like this:
{"Items":
[
{"Title":"Text","Type" : 1,...},
{"Title":"Text","Type" : 0,...},
{"Title":"Text","Type" : 0,...},
{"Title":"Text","Type" : 1,...},
{"Title":"Text","Type" : 0,...}
]
}
in my AMP project, I used something like this:
<div [class]="{{type}} == 0 ? 'class-0' : 'class-0' ">DATA</div>
but this will only work when the state changes, not in rendering for first time. Is there any way around this?

As far as I know it is impossible to evaluate bind expressions on page load. The docs clearly say as follows :
For performance and to avoid the risk of unexpected content jumping, amp-bind does not evaluate expressions on page load. This means that the visual elements should be given a default state and not rely amp-bind for initial render.
However amp-access can perform conditional rendering on page load without user interaction. Depending on your requirement you should be able to achieve this using amp-access.

Related

Ng-grid with external data and TypeScript: compile error "Cannot set property 'gridDim' of undefined"

Update #1: after the fix I commented about, now my app starts but the grid is not rendered except for its bounding box and filter button and popup. Yet, I get no error from the console, and as far as I can arrive with the debugger, I can see that data got from the server are OK. If I use Batarang, I can see the scope corresponding to my model, correctly filled with items. I updated the downloadable repro solution accordingly. Could anyone explain why ng-grid is not updating here?
I'm starting to play with ng-grid and TypeScript and I'm finding issues as soon as my test app starts up. See the bottom of this post for a link to a full test solution. Surely I have made tons of errors even in these few files, but I'd like to have something to start with and learn more step by step.
The MVC app has two client-side applications:
app.js for the default view (Home/Index). No typescript here, and the whole code is self-contained in this single file. The code is derived from the paging example in the ng-grid documentation and tries to stay as simplest as possible.
MyApp.js for the more realistic sample in another view (Home/Model). This sample uses services, models and controllers and its JS code is compiled from TypeScript. To keep things simple, I'm just storing these components under Scripts/App, in folders for Controllers, Models and Services, and each file contains just a single class or interface. The generated JS files are manually included in the view.
app.js works, except that it has issues with filtering. I posted about these here:
Server-side filtering with ng-grid: binding issue?
MyApp.js has startup issues with ng-grid. As soon as the app starts, a TypeError is thrown in the grid binding:
TypeError: Cannot set property 'gridDim' of undefined
at ngGridDirectives.directive.ngGridDirective.compile.pre (http://localhost:55203/Scripts/ng-grid-2.0.7.js:2708:37)
at nodeLinkFn (http://localhost:55203/Scripts/angular.js:4392:13)
at compositeLinkFn (http://localhost:55203/Scripts/angular.js:4015:15)
at nodeLinkFn (http://localhost:55203/Scripts/angular.js:4400:24)
at compositeLinkFn (http://localhost:55203/Scripts/angular.js:4015:15)
at publicLinkFn (http://localhost:55203/Scripts/angular.js:3920:30)
at resumeBootstrapInternal (http://localhost:55203/Scripts/angular.js:983:27)
at Object.$get.Scope.$eval (http://localhost:55203/Scripts/angular.js:8057:28)
at Object.$get.Scope.$apply (http://localhost:55203/Scripts/angular.js:8137:23)
at resumeBootstrapInternal (http://localhost:55203/Scripts/angular.js:981:15) <div ng-grid="gridOptions" style="height: 400px" class="ng-scope"> angular.js:5754
The only similar issue I found by googling is https://github.com/angular-ui/ng-grid/issues/60, but it does not seem to be related to my case as there the grid options were setup too late.
The server side just has an API RESTful controller returning server-paged, sorted and filtered items.
You can find the full repro solution here (just save, unzip and open; all the dependencies come from NuGet); see the readme.txt file for more information:
http://sdrv.ms/167gv0F
Just start the app and click MODEL in the upper right corner to run the TypeScript app throwing the error. The whole app is composed of 1 controller, 1 service and 1 model.
For starters like me, it would be nice to have a simple working example like this one. Could anyone help?
This error means gridOptions has not yet been defined by the time that Angular attempts to parse ng-grid="yourArray", where yourArray is the same array supplied to gridOptions. I had the same problem after refactoring a previously working ng-grid.
So gridOptions must be defined before the element which has ng-grid="yourArray" attribute applied to it (rather than within that element's own controller).
I resolved this by defining gridOptions in an outer element somewhere (on global/app scope, for instance).
P.S. Maybe there is a better way, but this has worked for me.
Where you are adding data to your grid?
If you are writing $scope.myGrid={data:"someObj"}; in a success call then it won't work.
See the below reason:(which is listed in https://github.com/angular-ui/ng-grid/issues/60)
You can't define the grid options in the success call. You need to define
them on the scope in your controller and then set the data or column
definitions, etc... from the success call.
What you have to do?, First is to see how this made ​​your project and revizar if your queries or data access, the beams through a service, if so this I must add the file that manages routes app, the client side.
remain so.
'use strict';
angular.module('iseApp', [
'ngCookies',
'ngResource',
'ngSanitize',
'ngRoute',
**'ngGrid',**
'campaignServices',
'dialinglistServices',
'itemServices'
])
.config(function ($routeProvider, $locationProvider, $httpProvider) {
$routeProvider
As you are adding your ng-grid in a directive, you have to make sure the grid options are loaded before it tries to parse your html.
You could set a boolean in your link function :
scope.isDirectiveLoaded=true;
And then, in your template, use a ng-if :
<div ng-if="isDirectiveLoaded">
<div ng-grid="myGrid"/>
</div>
I got to the same issue, empty grid was rendered.
The way I got to it in the end was to setup my this.gridOptions in the constructor of the controller, within the component. In the options everything is referenced with $ctrl like this. So the data references $ctrl.gridData. gridData is specified as a property in my component controller. $ctrl is not defined as a property.
This was done in the constructor before the data was loaded. this.gridData was defined after in the constructor and then populated later in another function. The options were defined first, I think this is important from some things I read.
For the event hooks pass null instead of $scope.
this.gridOptions = {
enableGridMenu: true,
minRowsToShow: 25,
rowHeight: 36,
enableRowHashing: true,
data: '$ctrl.gridData',
rowTemplate: this.$rootScope.blockedRowTemplate,
onRegisterApi: ($ctrl) => {
this.gridApi = $ctrl;
this.gridApi.colMovable.on.columnPositionChanged(null, (colDef, originalPosition, newPosition) => {
this.saveState();
});
this.gridApi.colResizable.on.columnSizeChanged(null, (colDef, deltaChange) => {
this.saveState();
});
this.gridApi.core.on.columnVisibilityChanged(null, (column) => {
this.saveState();
});
this.gridApi.core.on.sortChanged(null, (grid, sortColumns) => {
this.saveState();
});
this.gridApi.core.on.filterChanged(null, (grid, sortColumns) => {
this.saveState();
});
}
};
In the row template I was referencing functions defined in my component. Before conversion to a component I referenced functions like this:
ng-click="grid.appScope.jumpToExport(row.entity);"
After conversion to the component I needed to add the $ctrl before the function name like this
ng-click="grid.appScope.$ctrl.jumpToExport(row.entity);"
And this is how the component is referenced in the html
<div ui-grid="$ctrl.gridOptions" ng-if="$ctrl.gridData.length != undefined && $ctrl.gridData.length > 0" class="data-grid" ui-grid-save-state ui-grid-resize-columns ui-grid-move-columns></div>

mvc4 jquery autocomplete items showing up as asterisks instead of readable data

I got my autocomplete stuff working well enough to see that it's returning some data when I type in a field--but the data shown in the dropdown below the textbox is just a vertical column of asterisks or list item bullets. (I can't really tell what they are.)
When I query the web service directly in the browser, it returns a Json array as expected which looks like this where, for example ?term=chi (I've added some line breaks for readability)
[
{"Name":"Chihuahua"},
{"Name":"Chinese Crested"},
{"Name":"Chinese Shar-Pei"},
{"Name":"Japanese Chin"},
{"Name":"Schipperke"}
]
My JavaScript looks like this:
$(function() {
$("#Breed").autocomplete({
source: "#Url.Action("BreedList", "Patient")"
});
});
like I say, my textbox in question (#Breed) does respond sort of like an autocomplete box, but the dropdown data is weird. Any ideas?
Although I did have a CSS bundling problem (somehow I had omitted the jquery ui css from my bundle), a bigger issue was that the Json returned by my service needed a lower case "value" property for each item. I was using the column name as cased on my Linq query. The tip that pointed me in the right direction on this came from the answer here: jQueryUI autoComplete returns back empty list

ExtJS/Sencha Touch 2 - How to grab an element/component with multiple classes in

I'm not sure if I'm going crazy. I've tested this on Kitchen sink also so it's not just me.
I've tried:
Ext.ComponentQuery.query('container[cls="blah"]');
Ext.ComponentQuery.query('container[cls~="blah"]');
But after it has a second class, it seems you can't get ahold of something by a class that it has.
Am I missing something or is this not possible?
If you go to http://dev.sencha.com/deploy/touch/e.../#demo/buttons
Ext.ComponentQuery.query('button')[0];
// returns element
Ext.ComponentQuery.query('button')[0].addCls('meep');
Ext.ComponentQuery.query('button[cls="meep"')[0];
// returns element
Ext.ComponentQuery.query('button')[0].addCls('blah');
Ext.ComponentQuery.query('button[cls="meep"')[0];
// returns undefined
Ext.ComponentQuery.query('button[cls~="meep"')[0];
// returns undefined
Because of what I expect and how the documentation words their DomQuery I think the above should work but is bugged.
I got around this by creating a new xtype and using that instead in ComponentQuery like so:
Ext.define('App.view.Deposit', {
extend: 'Ext.Container'
});
Ext.ComponentQuery('meep');
I guess I was trying to go about it like you would in jQuery, add a class and retrieve it using that, but with the Component stuff it's confusing.
I think this SHOULD have worked but it does not (tested in 2.0.1.1, 2.1.0b3):
Ext.ComponentQuery.query('button[cls*="meep"')[0];

In Dojo how to add node to a tree in a sorted way?

In my Dojo application, I had a tree with nodes sorted by their name. Like this :
I already built a New form addition, and it can add a new node to this tree, but always at the bottom. Is there a way to insert this newly added node to the store in a correct sorted position? So if I am about to add 000-011 - Biaya Teknis Pengacara to this tree, it should be ended up this way :
To achieve this, currently I must refresh my browser. Surely, this is not what all user wanted.. :)
For the code addition of node itself, here it is:
//TOFIX : add in a sorted way
akunStore.newItem(
{"id":data.id.toString(),"name":data.name},
{"parent": groupsModel.root, "attribute":"groups"}
);
akunStore.save();
akunStore.fetch();
I add the fetch() as shown above, but it didn't work, currently.
Use the sort attribute in your call to the fetch() method of your data store. Try something like :
akunStore.fetch({
sort: [
{ attribute: "youFirstSortField" },
{ attribute: "aSecondSortField" }
]
});
You can also specify a descending order by adding "descending : true" in your sort params... more on that here : http://dojotoolkit.org/reference-guide/quickstart/data/usingdatastores/sorting.html#quickstart-data-usingdatastores-sorting

Dojo/Dijit: Can't get filtering select to work

I have a page with some JavaScript and it includes dojo.parser and has parseOnLoad set to true and whatnot.
Later in the page, I have another JavaScript tag that has:
dojo.require('dijit.form.FilteringSelect');
dojo.registry.remove('ID OF SELECT BOX');
After all that, I have a select box with dojoType="dijit.form.FilteringSelect".
Whenever I load the page, I get:
undefined Could not load class 'dijit.form.FilteringSelect'. Did you spell the name correctly and use a full path, like 'dijit.form.Button'?
Any ideas why? If I put the require statement in the first JavaScript tag, it works (but that tag is in a more global file, so I don't want it there).
dojo.registry is not correct. we have only dijit.registry.remove function. Maybe that is causing the problem.