I am a couchdb newbie running CouchDB 1.0.1.
I have a very basic issue. I cannot get Mustache Sections to render in a list.
Here is my list with the data hard coded from an example.
function(head, req) {
start({
"headers": {
"Content-Type": "text/html"
}
});
var mustache = require("lib/mustache");
var view = {name: "Joe's shopping card",items: ["bananas", "apples"]};
var template = "{{name}}: <ul> {{#items}}<li>{{.}}</li>{{/items}} </ul>";
return mustache.to_html(template,view);
Outputs:
Joe's shopping card: <ul> <li></li><li></li></ul>
Please help!!!
Thank you,
/ Jeff
Oh barf, I just figured it out and it is a little rediculous. Here it is for anyone else who wants to save some time. Add this to your template "{{%IMPLICIT-ITERATOR}}".
So:
var template = "{{name}}: <ul> {{#items}}<li>{{.}}</li>{{/items}} </ul>";
Becomes:
var template = "{{%IMPLICIT-ITERATOR}}{{name}}: <ul> {{#items}}<li>{{.}}</li>{{/items}} </ul>";
Related
beginner in programming, for a django(2.1) project i have added a leaflet-geosearch control on a map. It works fine but my need is to have this control in admin(LeafletGeoAdmin). I absolutely don't know how to do that. Thanks to anyone who can help me with this.
Here is what i have added in my template to displate the map with the geosearch control:
...
....
<div id="leafleft_container">
{% leaflet_map "map" callback="mapInit" %}
<script type="text/javascript">
var GeoSearchControl = window.GeoSearch.GeoSearchControl;
var OpenStreetMapProvider = window.GeoSearch.OpenStreetMapProvider;
var provider = new OpenStreetMapProvider();
var searchControl = new GeoSearchControl({
provider: provider,
searchLabel: 'Lieu à rechercher',
notFoundMessage: 'Non trouvé',
retainZoomLevel: true,
showMarker: true,
selected: 0,
autoClose:true,
keepResult:true
});
var map = L.map('map');
var osmUrl='https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png';
var osmAttrib='Map data © OpenStreetMap';
var osm = new L.TileLayer(osmUrl, {attribution: osmAttrib});
map.setView({{Centrage}}, 4);
map.addLayer(osm);
map.addControl(searchControl);
...
I guess to have the same result in admin I should add the same somewhere in leaflet widget but I have no idea where.
one solution was to add the leaflet-geosearch code into leaflet-extrajs and link the CDN for leaflet geo-search into widget.html.
Not sure it is the best practice but it works.
I want to delete the the Page with custom button. I have searched the the whole but found nothing. I have tried to find the ID of Delete button from Ribbon. But this also does not work.
I found a link but it does not help me.
[1] :https://sharepoint.stackexchange.com/questions/19887/custom-delete-page-button
Anyone here know about the solution.
I am surprised that no one have answer the question. Then I go deeper in Sharepoint and find a Solution to delete the page with custom Button or link.
So i decided to share with you guys. May be someone in future need this. I have achieve this through Javascript.
function deletePage() {
var url = document.location.pathname;
var urls = url.split("/");
var newurl = urls[1].concat("/", urls[2], "/", urls[3], "/Pages/Forms/AllItems.aspx");
var context = SP.ClientContext.get_current();
var web = context.get_web();
var folder = web.getFolderByServerRelativeUrl(url);
var confirmDelete = confirm("Do you want to delete this news ??");
if (confirmDelete) {
folder.deleteObject();
}
//if (confirmDelete) {
// window.location = "/" + newurl;
//}
context.executeQueryAsync(
function () {
if (confirmDelete) {
window.location = "/" + newurl;
}
}
);
}
And Just call this function onclick.
<li><i class="fa fa-close"></i>Delete</li>
Well this is working perfect.
Thanks
I'm using the Articles and Users implementation into Meanjs built-in app.
List of articles (View) with the button for every item:
<a data-ng-controller="MyArticlesController" data-ng-repeat="article in articles" class="list-group-item">
<button data-ng-click="addArt2me()" class="glyphicon glyphicon-plus addArt2me" ></button>
<h4 class="list-group-item-heading" data-ng-bind="article.title"></h4>
<p> {{article.content | limitTo:140}} </p>
</a>
And here the controller with the trigger function $scope.addArt2me():
'use strict';
angular.module('users').controller('MyArticlesController', ['$scope', 'Articles', 'Users', '$location',
function($scope, Articles, Users, $location) {
var myUser = new Users($scope.user);
$scope.addArt2me = function() {
var myArticle = new Articles($scope.article);
myUser.userArticles.push(myArticle._id);
myUser.$update(function(response) {
console.log("Actualize!! con : " + user.userArticles.length + "__" + response);
}, function(errorResponse) {
console.log("updatError: " + errorResponse);
$scope.error = errorResponse;
});
}
}
]);
In the user's model I've an array of articles._id userArticles.
The View renders a list of articles with a button that triggers the function addArt2me() in the controller, which pushes and updates the myArticle._id inside ´userArticles´.
It works successfully and saves the element into DB :)
console: Actualize!! con : 60__[object Object]
...but only the first time, the next time it triggers an error :(
PUT http://localhost:3000/users 400 (Bad Request)
updatError: [object Object]´
Do I need to deal with some kind of service to update the USERS module being in ARTICLES module?
Can't I just update the model of the user with Mongoose?
Why does it works well for the first saved article ?
Any guide is very appreciated. Thanks!
I just founded, after 2 day of looking for it.
Needed to declare the User Model, outside the subcontroller because it iterates for every article.
so move ´$scope.myUser = new Users($scope.user);´ into ´ArticlesController´ Did the job!
Thanks for your time!
I am creating an application to get some experience in jQuery Mobile and backbone. I have made a "restful" API with node.js that handles the data I need. It works fine with all my static pages I made in index.html. But when I need to create a page with data from a certain id I am a bit lost.
For example when I want to display all items(/items) I have a data-role=page with id items that list all items, but when I need to go to a detailed page for each item (/items/1) i want to create that details page whenever a user wants details on an item, in other words when a user visit the url spots#3 for example.
Is this possible?
my router: the model gives me all data i want
Spoter.Router = Backbone.Router.extend({
routes: {
"": "",
"spot#:id": "spotDetails"
},
//Details on a certain spot with id
spotDetails: function(id) {
var spotDetailsContentDiv = Spoter.spotDetailsContent;
spotDetailsContentDiv.empty();
var spot = new Spoter.spotModel({id: id});
spot.fetch({
successCallback: function(data) {
var spotDetailsView = new Spoter.spotDetailsView({
model: data
});
spotDetailsContentDiv.html(spotDetailsView.render().el);
}
});
}
});
View:
Spoter.spotDetailsView = Backbone.View.extend({
render:function () {
this.$el.html(this.template(this.model));
return this;
}
});
Template with underscore
<ul data-role="listview" data-theme="c" data-inset="true">
<li>
<a href="#">
<h1><%= this.model.name %></h1>
<p><%= this.model.description %></p>
</a>
</li>
</ul>
I've got template file loaded by Require.js via this:
main-app.js
define([
'backboneLoader',
'handlebars',
'text!templates/main.html',
'text!appdata.json'
],
function(
Backbone,
Handlebars,
MainTemplate,
AppData
) {
"use strict";
return Backbone.View.extend({
initialize : function() {
this.render();
},
render : function() {
var template = Handlebars.compile(MainTemplate);
var output = template(AppData);
this.$el.append(output);
console.log("appData:\n" + AppData);
console.log("MainTemplate:\n" + MainTemplate);
console.log("Output:\n" + output);
//smth extra
return this;
}
});
}
);
MainTemplate (main.html)
<ul>
<li><b>Version:</b> {{version}}</li>
<li><b>Author:</b> {{author}}</li>
</ul>
AppData (appdata.json)
{version: "0.0.1", author: "John Doe"}
And output:
<ul>
<li><b>Version:</b></li>
<li><b>Author:</b></li>
</ul>
While expected output:
<ul>
<li><b>Version:</b> 0.0.1</li>
<li><b>Author:</b> John Doe</li>
</ul>
Any ideas what am I doing wrong? Thank you!
UPD:
Problem solved. Here is updated main-app.js:
define([
'backboneLoader',
'handlebars',
'text!templates/main.html!strip',
'text!appdata.json'
],
function(
Backbone,
Handlebars,
mainTemplate,
appData
) {
"use strict";
return Backbone.View.extend({
initialize : function() {
this.render();
},
render : function() {
var template = Handlebars.compile(mainTemplate);
var output = template(eval("(" + appData + ")")); //Object is expected by template(), not JSON.
this.$el.append(output);
console.log("appData:\n" + appData);
console.log("template:\n" + mainTemplate);
console.log("Output:\n" + output);
//smth extra
return this;
}
});
}
);
The problem is AppData is a string of JSON, not an actual Object. Simply change from:
var output = template(AppData);
to
var output = template(JSON.parse(AppData));
You may need to include json2.js to add JSON support for older browsers (<=IE7).
Here is a jsFiddle repro of your template function, the template transformations seems working, the problem is probably located in the text! function in require.js code, try to debug the text! function.
Try also to add the !strip function when loading the template: 'text!templates/main.html!strip',
The documentation suggests it :For HTML/XML/SVG files, there is another option. You can pass !strip, which strips XML declarations so that external SVG and XML documents can be added to a document without worry.