Чтение строк отлично работает в сетке, но при обновлении и создании он вообще не работает. Он не попадает в контроллер. Я предоставил код, можете ли вы посмотреть, что не так с приведенным ниже кодом.Kendo UI Обновление и создание не работает
The below json is return from the read webservice
-------------------------------------------------
{"items":[{"id":1,"publisherName":"Srini","active":false}, {"id":2,"publisherName":"Ram","active":false}]}
<!-- JAVASCRIPT FILES -->
<script src="../bootstrap/js/bootstrap.js"></script>
<script src="../jquery/plug-ins/colorbox-modal/jquery.colorbox.js"></script>
<script src="../jquery/plug-ins/colorbox-modal/colorbox.js"></script>
<script src="../jquery/plug-ins/jquery.placeholder.js"></script>
<script src="../jquery/plug-ins/jquery.jOrgchart.js"></script>
<script src="../bootstrap/js/bootstrap-prettyCheckable.js"></script>
<script src="../bootstrap/plug-ins/bootstrap-datepicker.js"></script>
<script src="../bootstrap/plug-ins/bootstrap-switch.js"></script>
<script src="../bootstrap/js/bootstrap-downloadFile.js"></script>
<script src="../bootstrap/js/bootstrap-select.js"></script>
<!-- Kendo UI Web combined JavaScript -->
<script src="../kendoUI/js/kendo.web.min.js"></script>
<div id="example">
<div id="grid"></div>
<script style="text/javascript">
jq(document).ready(function() {
dataSource = new kendo.data.DataSource({
dataType: "json",
transport: {
read: {
url:BASE_URL + "admin/searchPublishers.htm",
type: "GET",
cache: false
},
update: {
url:BASE_URL + "admin/updatePublisher.htm",
type: "POST"
},
create: {
url: BASE_URL + "admin/createPublisher.htm",
type: "POST"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
schema: {
model: {
fields: {
id: {
type: "number"
},
publisherName: {
type: "string"
}
}
},
data: "items",
total: "items.length" //total amount of records. This is needed for paging
},
pageSize: 20
});
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
height: 550,
toolbar: ["create"],
columns: [
{ field: "publisherName", title: "Publisher", width: "130px" },
{ command: ["edit"], title: "Actions", width: "150px" }
],
editable: "inline"
});
});
</script>
</div>
Java Controller
---------------
package com.wad.webui.controller;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;
import com.wad.core.model.lookup.PublisherLookupItem;
/**
* @author Srinivasa.K
*
*/
@Controller
public class PublisherController extends BaseController {
private static final Logger logger = Logger
.getLogger(PublisherController.class);
private static final List<PublisherLookupItem> publishersList = new ArrayList<PublisherLookupItem>();
static {
PublisherLookupItem pb = new PublisherLookupItem();
pb.setId(1);
pb.setPublisherName("Srini");
PublisherLookupItem pb1 = new PublisherLookupItem();
pb1.setId(2);
pb1.setPublisherName("Ram");
publishersList.add(pb);
publishersList.add(pb1);
}
@RequestMapping(value = "/admin/searchPublishers.htm", method = RequestMethod.GET, produces = "application/json")
public @ResponseBody
JsonDataWrapper<PublisherLookupItem> searchPublishers(
HttpServletRequest request) throws Exception {
logger.debug("searchPublishers method ");
JsonDataWrapper<PublisherLookupItem> result = new JsonDataWrapper<PublisherLookupItem>(
publishersList);
return result;
}
@RequestMapping(value = "/admin/updatePublisher.htm", method = RequestMethod.POST, produces = "application/json")
public @ResponseBody
PublisherLookupItem updatePublisher(
@RequestBody PublisherLookupItem target, HttpServletRequest request)
throws Exception {
System.out.println("updatePublisher method :" + target);
publishersList.add(target);
return target;
}
@RequestMapping(value = "/admin/createPublisher.htm", method = RequestMethod.POST, produces = "application/json")
public @ResponseBody
PublisherLookupItem createPublisher(
@RequestBody PublisherLookupItem target, HttpServletRequest request)
throws Exception {
System.out.println("createPublisher method :" + target);
publishersList.add(target);
return target;
}
}
Привет, когда попробуйте оповещение (options.data.id); он приходит как неопределенный. и это причина, по которой newitem имеет только активный: false. что нужно сделать для решения проблемы? – user3157090
Вы уверены, что это ваш полный результат Json от поисковых издателей. где «Элементы»: {"items": [{"id": 1, "publisherName": "Srini", "active": false}, {"id": 2, "publisherName": "Ram "," active ": false}]} – cwishva
Попробуйте мое обновление, определите схему как это, также поставьте этот« console.log (JSON.stringify (options.data) »перед var newitem = []; и дайте мне знать, что вы видите на консоли – cwishva