なぜアイテムをアレイから削除できないのですか?'this.list.remove'を評価しているときに未定義のオブジェクトがありません
私は、配列のすべてのオブジェクトを表示しようとしていますHTMLビュー、:
<tbody data-bind="foreach:list" >
<tr>
<td data-bind="text:name" class="span10"></td>
<td><a class="icon-pencil" href="#"></a>Edit</td>
here every time you click at the <a> tag i want to remove an element of the array. but it is not working
<td><a class="icon-trash" href="#" data-bind="click:$root.removeItem " >
</a>Delete</td>
</tr>
</tbody>
スクリプト:あなたは、私が
self:this,
self.list : ko.observableArray(customers),
を次のように
$(function() {
var customers=[
{name:'robert'},
{name:'miguel'},
{name:'felipe'},
{name:'juan'},
{name:'danilo'},
{name:'federico'}
];
var viewModel = {
self:this,
list: ko.observableArray(customers),
// it's not removing the item of the array.
removeItem: function(place) {
this.list.remove(place);
}
};
ko.applyBindings(viewModel);
});
構文エラーのようになります。完全に実行可能な例にその最後の提案トン。 'self.list'はそのようなオブジェクトのキーとしては機能しません。 – DonovanM
実際に彼は観測可能に彼の配列を入れていなかったので、それは私が思うに動作しないように何かを削除しようとした –