-5
因此,使用JS打造 '產品'JS產品排行榜犯規獲得。長度
<script type="text/javascript" language="javascript">
var products = [
@{
bool addComma = false;
foreach (UMACS.Bradmount.Models.QBProductRecord product in Model.AllProducts)
{
if (addComma)
{
<text> @Html.Raw(",") </text>
}
<text> @Html.Raw(string.Format("{{ value: \"{0} ({1})\", label: \"{0} ({1})\", desc: \"{1}\", prodid: \"{2}\" }}", product.ProductCode.Stripped(), product.ProductName.Stripped(), product.Id)) </text>
addComma = true;
}
}
];
所以這個產品是這樣的:
// {
// value: "CARSLI5",
// label: "CARSLI5",
// desc: "Carrots Sliced 5kg",
// prodid: "43"
// },
// {
// value: "CARBAT5",
// label: "CARBAT5",
// desc: "Carrots Baton 5kg",
// prodid: "24"
// }
// ];
然後後來我想說
self.selectedProductId = ko.computed(function() {
for (var i = 0; i < products.length; i++) {
if (products[i].label == self.selectedProduct()) {
return products[i].prodid;
}
}
return "0";
其中products.length表示產品不存在?任何想法爲什麼?
你的產品列表中包含Javascript和HTML?好像。 。 。瘋。 – Julio
如果產品是一個對象,它沒有長度屬性 –
如果產品的定義如你所說,那麼它有一個長度屬性(http://jsfiddle.net/sperske/Y6HUU/)。我的猜測是有更多這個問題 –