我将数组绑定到ons-list。在更新arraylist时,必须更新ons-list。有没有选择像双向绑定?
我尝试了$ scope。$ watch,但返回" undefined"
答案 0 :(得分:1)
我认为你使用角度,这是一个例子:
<强> HTML 强>
<ons-list id="content" ng-controller="MyCtrl">
<ons-list-header>Persons</ons-list-header>
<ons-list-item ng-repeat="person in persons">{{person.name}}</ons-list-item>
</ons-list>
<ons-button onclick="addNewPerson()">Click to Add a Person</ons-button>
<强> JS 强>
ons.bootstrap();
var theList = [{name: "John", age: 46},{name: "Debbie", age: 26}, {name: "Leslie", age: 35}];
function MyCtrl($scope, $rootScope) {
$scope.persons = theList;
}
function addNewPerson() {
var newPerson = {name: "Larry", age: 16};
theList.push(newPerson);
//alert(theList.length);
//alert(document.getElementById("content"));
var scope = angular.element(document.getElementById("content")).scope();
scope.persons = theList;
myNavigator.resetToPage("myPage");
}
在此处观看:&#39; http://codepen.io/vnguyen972/pen/eLlzh&#39;