-1
所以我想要做的是從客戶端更新,並在後端更新。我正在使用MEAN堆棧來完成此操作。目前,我可以獲取我想要更新的單個項目的ID,但無法弄清楚我缺少更新數據庫中的項目。MEAN堆棧更新函數
這裏是我的HTML代碼:
<h1>Sorting Books</h1>
<div ng-init="getBooks()"></div>
<p><input type="text" ng-model="test" placeholder="Search..."></p>
<p><select ng-model="category" ng-options="x for x in categoryNames">Category</select></p>
eBook: <input type="checkbox" ng-model="eBook">
<ul ng-repeat="book in allTheBooks | filter:test | filter:category | filter: eBook">
<li><strong>Title: </strong><span editable-text="book.title" e-name="name" e-form="editableForm" e-required>{{book.title}}</span></li>
<ul>
<li><strong>Category: </strong><span editable-text="book.category" e-name="name" e-form="editableForm" e-required>{{book.category}}</span></li>
<li><strong>eBook: </strong><span editable-text="book.eBook" e-name="name" e-form="editableForm" e-required>{{book.eBook?'Yes':'No'}}</span></li>
<li><strong>Volume: </strong><span editable-text="book.volume" e-name="name" e-form="editableForm" e-required>{{book.volume}}</li>
<li><strong>Author: </strong><span editable-text="book.author" e-name="name" e-form="editableForm" e-required>{{book.author}}</li>
<li><strong>Genre: </strong><span editable-text="book.genre" e-name="name" e-form="editableForm" e-required>{{book.genre}}</li>
<li><strong>Stars: </strong><span editable-text="book.stars" e-name="name" e-form="editableForm" e-required>{{book.stars}}</li>
<li><strong>Comments: </strong><span editable-text="book.comments" e-name="name" e-form="editableForm" e-required>{{book.comments}}</li>
<li><button type="button" ng-click="deleteBook(book._id)">Delete</button></li>
<li>
<form editable-form name="editableForm" onaftersave="saveUser()">
<div>
<button type="button" class="btn btn-default" ng-click="editableForm.$show(); update(book._id);" ng-show="!editableForm.$visible">Edit</button>
<span ng-show="editableForm.$visible">
<button type="submit" class="btn btn-primary" ng-disabled="editableForm.$waiting">Save</button>
<button type="button" class="btn btn-default" ng-disabled="editableForm.$waiting" ng-click="editableForm.$cancel()">Cancel</button>
</span>
</div>
</form>
</li>
</ul>
</ul>
這裏是我的script.js代碼:
$scope.update = function(id){
console.log('figuring things out... ' , id);
};//end of Update
現在有了這個我已經嘗試了多種不同的東西,$ scope.book.title,等等,但給出'不能讀取屬性'標題'未定義'的錯誤。'
這裏是我的app.js代碼:
app.put('/bookUpdate/:id', function (req, res) {
var bookId = req.params.id;
console.log('from app.js ' , bookId);
});//end of app.update function
我開到什麼真的,我已經嘗試了多種不同的東西幾乎沒有成功。讓我知道你是否需要更多的代碼說明。
在此先感謝!
-Maykid
如果你是在一個循環,allTheBooks是一個數組,「書」是NG重複內的局部變量,你的更新功能應該作爲PARAM整個「書」對象:更新(書)。不只是身份證。無論如何,這看起來很亂。你爲什麼不直接編輯一個單獨的記錄來代替這個ng-repeat混亂 – yBrodsky
你正在使用哪個版本的x-editable? – georgeawg