I need to find a report among the reports observable array by Id. How am I supposed to write the underscore
statement?
I am using:
_.where(reports(), {id:data.ReportId})
and
_.where(reports(), {id:ko.observable(data.ReportId)})
It always return an empty array.
Then I find out some underscoreKO.js
, but it still won't work. Can someone help me? Thanks.
There is another similar post here, but they are not exactly the same. ko.utils.arrayFirst
can locate the item, but won't help me update it.
The correct answer came from Daniel A. White, with a little change. Thank you.
One correction:
var record = _.filter(reports(), function (item) { return item.id() == data.ReportId; })
if (record.length > 0) {
_.first(record).reportStatus("Approved");
}
I find it has to be item.id()
instead of just id()
. But a million thanks to Daniel!