显示ember.js中的项目数(display number of items in ember.js)
我需要一个非常简单的事情,并在网上查找已建立的解决方案,告诉我我的代码是正确的。 但显然不是。 我只需要在我的应用中显示我有多少笔记(模型):
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> Notes and bookmarks </title> <link rel="stylesheet" href="css/style.css"> </head> <body> <script type="text/x-handlebars" data-template-name="index"> <div class="wrap"> <div class="bar"> <input type="text" class="search" /> <div class="bar-buttons"> <button> NEW </button> <button> HOME </button> </div> </div> <aside> <h4 class="all-notes">All Notes {{all}}</h4> {{#each item in model}} <li> {{#link-to 'note' item}} {{item.title}} {{/link-to}} </li> {{/each}} </aside> {{outlet}} </div> </script> <script type="text/x-handlebars" data-template-name="main"> <section> <h2>Hellooo</h2> </section> </script> <script type="text/x-handlebars" data-template-name="note"> <section> <div class="note"> {{#if isEditing}} <h2 class="note-title input-title"> {{edit-input-note value=title focus-out="modified" insert-newline="modified"}} </h2> <p class="input-body"> {{edit-area-note value=body focus-out="modified" insert-newline="modified"}} </p> {{edit-input-note value=url focus-out="modified" insert-newline="modified"}} {{else}} <h2 {{action "editNote" on="doubleClick"}} class="note-title" > {{title}} </h2> <button {{action "removeNote"}} class="delete"> Delete </button> <p {{action "editNote" on="doubleClick"}}> {{body}} </p> {{input type="text" placeholder="URL:" class="input" value=url }} {{/if}} </div> </section> </script> <script src="js/libs/jquery-1.9.1.js"></script> <script src="js/libs/handlebars-1.0.0.js"></script> <script src="js/libs/ember-1.1.2.js"></script> <script src="js/libs/ember-data.js"></script> <script src="js/app.js"></script> <script src="js/router.js"></script> <script src="js/models/note_model.js"></script> <script src="js/controllers/note_controller.js"></script> <script src="js/controllers/notes_controller.js"></script> <script src="js/views/note_view.js"></script> </body> </html>
我的模特:
Notes.Note = DS.Model.extend ({ title: DS.attr('string'), body: DS.attr('string'), url: DS.attr('string') }); Notes.Note.FIXTURES = [ { id: 1, title: 'hello world', body: 'ciao ciao ciao ciao', url: '' }, { id: 2, title: 'javascript frameworks', body: 'Backbone.js, Ember.js, Knockout.js', url: '...' }, { id: 3, title: 'Find a job in Berlin', body: 'Monster, beralinstartupjobs.com', url: '...' } ]
我的笔记控制器:
Notes.NotesController = Ember.ArrayController.extend ({ all: function () { var notes = this.get('model'); return notes.get('lenght'); }.property('model') });
我认为这是使这项工作的所有重要代码,但如果你需要其他部分我将添加。 为什么我在{{all}}中看不到我的笔记数量?
I need a very easy thing and looking on the web the solutions founded tell me that my code is right. But clearly isn't. I just need to display how many notes(models) I have in my app:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> Notes and bookmarks </title> <link rel="stylesheet" href="css/style.css"> </head> <body> <script type="text/x-handlebars" data-template-name="index"> <div class="wrap"> <div class="bar"> <input type="text" class="search" /> <div class="bar-buttons"> <button> NEW </button> <button> HOME </button> </div> </div> <aside> <h4 class="all-notes">All Notes {{all}}</h4> {{#each item in model}} <li> {{#link-to 'note' item}} {{item.title}} {{/link-to}} </li> {{/each}} </aside> {{outlet}} </div> </script> <script type="text/x-handlebars" data-template-name="main"> <section> <h2>Hellooo</h2> </section> </script> <script type="text/x-handlebars" data-template-name="note"> <section> <div class="note"> {{#if isEditing}} <h2 class="note-title input-title"> {{edit-input-note value=title focus-out="modified" insert-newline="modified"}} </h2> <p class="input-body"> {{edit-area-note value=body focus-out="modified" insert-newline="modified"}} </p> {{edit-input-note value=url focus-out="modified" insert-newline="modified"}} {{else}} <h2 {{action "editNote" on="doubleClick"}} class="note-title" > {{title}} </h2> <button {{action "removeNote"}} class="delete"> Delete </button> <p {{action "editNote" on="doubleClick"}}> {{body}} </p> {{input type="text" placeholder="URL:" class="input" value=url }} {{/if}} </div> </section> </script> <script src="js/libs/jquery-1.9.1.js"></script> <script src="js/libs/handlebars-1.0.0.js"></script> <script src="js/libs/ember-1.1.2.js"></script> <script src="js/libs/ember-data.js"></script> <script src="js/app.js"></script> <script src="js/router.js"></script> <script src="js/models/note_model.js"></script> <script src="js/controllers/note_controller.js"></script> <script src="js/controllers/notes_controller.js"></script> <script src="js/views/note_view.js"></script> </body> </html>
My model:
Notes.Note = DS.Model.extend ({ title: DS.attr('string'), body: DS.attr('string'), url: DS.attr('string') }); Notes.Note.FIXTURES = [ { id: 1, title: 'hello world', body: 'ciao ciao ciao ciao', url: '' }, { id: 2, title: 'javascript frameworks', body: 'Backbone.js, Ember.js, Knockout.js', url: '...' }, { id: 3, title: 'Find a job in Berlin', body: 'Monster, beralinstartupjobs.com', url: '...' } ]
And my notes controller:
Notes.NotesController = Ember.ArrayController.extend ({ all: function () { var notes = this.get('model'); return notes.get('lenght'); }.property('model') });
I think that's all the important code for make this work but if you need others part I will add. Why i can't see the number of my notes in {{all}} ?
原文:https://stackoverflow.com/questions/19694474
最满意答案
最简单的方法可能是创建一个带有内容的(临时)
FileHandle
并使用它来加载地图。默认情况下,
TmxMapLoader
将使用InternalFileHandleResolver
。 这不起作用,因为您无法在运行时创建内部文件。这就是为什么你要使用
ExternalFileHandleResolver
作为地图加载器,创建一个外部文件并将当天的地图写成一个字符串。String mapOfTheDay = ...; FileHandle mapOfTheDayFile = Gdx.files.external("mygame/mapoftheday.tmx"); mapOfTheDayFile.writeString(mapOfTheDay, false); TiledMap tileMap = new TmxMapLoader(new ExternalFileHandleResolver()).load("mygame/mapoftheday.tmx");
The easiest way would probably be to create a (temporary)
FileHandle
with the content and use that to load the map.By default
TmxMapLoader
will use anInternalFileHandleResolver
. This won't work, because you cannot create internal files at runtime.That's why you would instead use an
ExternalFileHandleResolver
for the map loader, create an external file and write your map of the day as a string into it.String mapOfTheDay = ...; FileHandle mapOfTheDayFile = Gdx.files.external("mygame/mapoftheday.tmx"); mapOfTheDayFile.writeString(mapOfTheDay, false); TiledMap tileMap = new TmxMapLoader(new ExternalFileHandleResolver()).load("mygame/mapoftheday.tmx");
相关问答
更多-
使用平铺地图文件时处理不同的屏幕显示(tmx)(dealing with different screensizes when using tiled map files (tmx))[2023-05-31]
TMX文件没有自动加载到iOS中,所以我猜你要么使用SKAToolKit ,要么使用JSTileMap ,这是我所知道的两个最受欢迎的版本之一。 我自己和其他Sprite Kit联盟成员将SKAToolKit放在一起,所以我想我可以从这个角度回答你的问题,因为它也应该与JSTileMap类似。 简短的回答是使用1x资产构建您的地图,但在Xcode中提供标准和视网膜的图像。 首先,使用1x资产创建地图。 加载地图时,它使用点而非像素。 因此,例如,如果您制作32x32像素图块地图,则将其视为32x32点图。 ... -
您可以在设置tiledMapRenderer.setView(cam);时添加偏移集tiledMapRenderer.setView(cam); 而不是那样做 float width = cam.viewportWidth *cam.zoom; float height = cam.viewportHeight * cam.zoom; float w = width * Math.abs(cam.up.y) + height * Math.abs(cam.up.x); float h = height * ...
-
我发现你可以缩放平铺地图。 所以你要做的就是 otmr = new OrthogonalTiledMapRenderer(tiledMap,SCREEN_WIDTH/(tiledMap.getProperties().get("width",Integer.class)*32f)); 其中32是瓷砖的大小,重要的是保持平铺地图的比例为16/9 i found out you can scale tiled map . so what you have to do is otmr = new Ortho ...
-
最简单的方法可能是创建一个带有内容的(临时) FileHandle并使用它来加载地图。 默认情况下, TmxMapLoader将使用InternalFileHandleResolver 。 这不起作用,因为您无法在运行时创建内部文件。 这就是为什么你要使用ExternalFileHandleResolver作为地图加载器,创建一个外部文件并将当天的地图写成一个字符串。 String mapOfTheDay = ...; FileHandle mapOfTheDayFile = Gdx.files.exter ...
-
您应该使用设置的最近纹理过滤器打包您的tileset。 如果您使用的是线性光标,则GL使用周围像素平均边界像素会导致像这样的毛刺。 阅读本文以获取有关LibGDX中纹理过滤器的更多信息。 You should pack your tileset with Nearest texture filter being set. If you are using Linear one the GL is averaging border pixels using surrounding one what cause ...
-
在android上平铺地图(tiled map on android)[2022-12-26]
这里有一个完整的开源地图引擎列表。 OSMand是最受欢迎的之一。 熟悉Openstreetmap网站是值得的。 你也可以从那里获得离线瓷砖。 So I ended up buying a library called mAppWidget from here: http://mapp.android-libraries.com It is pretty cool library and worth the money. -
在TiledMapRenderer顶部渲染动画,以更改渲染顺序。 @Override public void render () { time = time + Gdx.graphics.getDeltaTime(); Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); renderer.setView(orthographicCamera); renderer.ren ...
-
我想这就是你要找的...... if(object instanceof TextureMapObject) { TextureMapObject mapObject = (TextureMapObject) object; this.bounds = new Rectangle(mapObject.getX(), mapObject.getY(), mapObject.getTextureReg ...
-
使用SharpMap的TileLayerAsync可以实现这一点。 请在此处查看TileLayerAsync示例。 您需要指定合适的切片源。 使用GeoServer的tile = true, 它看起来仍然将它作为普通WMS发布,但考虑到标签放置。 在这种情况下,你需要这样的东西 也许更好的方法是使用GeoServer将其作为使用TMS,WMTS或WMS-C的适当切片层发布。 在这种情况下,您需要通过BruTile的HttpTileSource访问它。 This is possible using Sharp ...
-
所以你想将屏幕坐标转移到世界坐标。 例如: @Override public void clicked(InputEvent event, float x, float y) { Vector3 touch = new Vector3(x, y, 0); camera.unproject(touch); System.out.println("Screen coordinates translated to world coordinates: " + "X: " ...