将元素添加到ListView的方法
A method to add an element to a ListView
是否有一个方法来添加一个元素到ListView?我的目标是在不绑定数据的情况下做到这一点!例如:
myListView.add("one");
myListView.add("two");
ecc
只需将该项目添加到初始列表中。如果你有绑定设置,这将自动发生。
Html <>之前<div id="simpleBinding" data-win-control="WinJS.UI.ListView"></div>
<div id="simpleBindingTemplate" data-win-control="WinJS.Binding.Template">
<h3 data-win-bind="innerText:name" />
<span>Name :</span><span data-win-bind="textContent: name"></span>
<img data-win-bind="src:imageUrl" />
</div>
之前Javascript <>之前
//Note you could also declare an object type to use here,
//and instantiate them in the list below
var Person = WinJS.Binding.define({
name: "",
birthday: ""
});
//Using the above object
//var people = [
// new Person({ name: "Bob", birthday: "2/2/2002" }),
// new Person({ name: "Sally", birthday: "3/3/2003" }),
// new Person({ name: "Fred", birthday: "2/2/2002" })
//];
//Or simply using JSON
var people = [{ name: 'mary', birthday: '1/1/2010' },
{ name: 'fred', birthday: '1/1/2012' }];
//create the binding wrapper
var simpleFriends = new WinJS.Binding.List(people);
//get the ref to your list view
var simpleListView = document.getElementById('simpleBinding').winControl;
//get your template
var simpleTemplate = document.getElementById('simpleBindingTemplate');
simpleListView.itemDataSource = simpleFriends.dataSource;
//can also set in the markup for this element
simpleListView.itemTemplate = simpleTemplate;
//add a new item. the binding update happens automatically
//Could use a Person object we defined
//simpleFriends.push(new Person({ name: "Dynamically added", birthday: "2/2/2002"}));
//or JSON
simpleFriends.push({ name: "Dynamically added", birthday: "2/2/2002"});
之前要删除项目,您可以使用pop或查看这篇文章的索引方法从WinJS.Binding.List中删除项
App Builder上有一些很好的绑定内容'Day 10' App Builder
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- 有没有任何方法可以将控制器从文件加载到ui路由器$stateProvider中
- 数组在递归方法中设置为null
- 打破承诺链的好方法是什么
- 在使用Polymer'加载所有json文件后执行方法;s的核心ajax
- 使用“;这个“;JavaScript原型方法中的关键字
- 序列化数据属性中对象的最可靠方法
- 使用Objective-C的JavaScript注入方法
- 有没有一种方法可以添加相同的项目val=“0”;4〃;到JavaScript中数组的每个对象
- 有没有一种方法可以防止img get请求使用css或js发生
- Javascript,有没有一种方法可以将数组写成没有逗号或空格的单个文本字符串
- toBoolean方法类似于toString
- 如何在单击复选框后调用控制器方法
- 是否有任何方法可以使用jQuery替换在数组中定义值的文本
- 递归使用 eval() 是检查程序执行的好方法吗?
- 什么'是删除WinJS ListView中所有项目的最快方法
- KendoUI Mobile ListView/MVM”;对象#<文本>没有方法'getAttrib
- 未捕获的类型错误:列表视图没有方法'listview'
- 有什么方法可以用javascript清除listview吗
- 将元素添加到ListView的方法